بنرهای هوشمند
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
پلتفرم را انتخاب کنید: Android iOS Unity بنرهای هوشمند واحدهای تبلیغاتی هستند که تبلیغات بنری با عرض صفحه را در هر اندازه صفحه در دستگاه های مختلف در هر جهت ارائه می کنند. بنرهای هوشمند عرض دستگاه را در جهت فعلی آن تشخیص می دهند و نمای تبلیغاتی را در آن اندازه ایجاد می کنند.
بنرهای هوشمند در آیفون ها دارای ارتفاع 50 نقطه در عمودی و 32 نقطه در افقی هستند. در iPads، ارتفاع 90 نقطه در هر دو حالت عمودی و افقی است.
وقتی یک تبلیغ تصویری به اندازه کافی بزرگ نباشد که کل فضای اختصاص داده شده را اشغال کند، تصویر در مرکز قرار می گیرد و فضای دو طرف پر می شود.

برای استفاده از بنرهای هوشمند، کافی است kGADAdSizeSmartBannerPortrait
(برای جهت عمودی) یا kGADAdSizeSmartBannerLandscape
(برای جهت افقی) را برای اندازه تبلیغ مشخص کنید:
سویفت
let bannerView = GADBannerView(adSize: kGADAdSizeSmartBannerPortrait)
هدف-C
GADBannerView *bannerView = [[GADBannerView alloc]
initWithAdSize:kGADAdSizeSmartBannerPortrait];
از آنجایی که منطقه امن برای iOS 11 اضافه شده است، برای بنرهای تمام عرض نیز باید محدودیت هایی برای لبه های بنر به لبه های منطقه امن اضافه کنید. در اینجا یک قطعه کد وجود دارد که نحوه انجام این کار را نشان می دهد:
سویفت
func addBannerViewToView(_ bannerView: GADBannerView) {
bannerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bannerView)
if #available(iOS 11.0, *) {
// In iOS 11, we need to constrain the view to the safe area.
positionBannerViewFullWidthAtBottomOfSafeArea(bannerView)
}
else {
// In lower iOS versions, safe area is not available so we use
// bottom layout guide and view edges.
positionBannerViewFullWidthAtBottomOfView(bannerView)
}
}
// MARK: - view positioning
@available (iOS 11, *)
func positionBannerViewFullWidthAtBottomOfSafeArea(_ bannerView: UIView) {
// Position the banner. Stick it to the bottom of the Safe Area.
// Make it constrained to the edges of the safe area.
let guide = view.safeAreaLayoutGuide
NSLayoutConstraint.activate([
guide.leftAnchor.constraint(equalTo: bannerView.leftAnchor),
guide.rightAnchor.constraint(equalTo: bannerView.rightAnchor),
guide.bottomAnchor.constraint(equalTo: bannerView.bottomAnchor)
])
}
func positionBannerViewFullWidthAtBottomOfView(_ bannerView: UIView) {
view.addConstraint(NSLayoutConstraint(item: bannerView,
attribute: .leading,
relatedBy: .equal,
toItem: view,
attribute: .leading,
multiplier: 1,
constant: 0))
view.addConstraint(NSLayoutConstraint(item: bannerView,
attribute: .trailing,
relatedBy: .equal,
toItem: view,
attribute: .trailing,
multiplier: 1,
constant: 0))
view.addConstraint(NSLayoutConstraint(item: bannerView,
attribute: .bottom,
relatedBy: .equal,
toItem: bottomLayoutGuide,
attribute: .top,
multiplier: 1,
constant: 0))
}
هدف-C
- (void)addBannerViewToView:(UIView *)bannerView {
bannerView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:bannerView];
if (@available(ios 11.0, *)) {
// In iOS 11, we need to constrain the view to the safe area.
[self positionBannerViewFullWidthAtBottomOfSafeArea:bannerView];
} else {
// In lower iOS versions, safe area is not available so we use
// bottom layout guide and view edges.
[self positionBannerViewFullWidthAtBottomOfView:bannerView];
}
}
#pragma mark - view positioning
- (void)positionBannerViewFullWidthAtBottomOfSafeArea:(UIView *_Nonnull)bannerView NS_AVAILABLE_IOS(11.0) {
// Position the banner. Stick it to the bottom of the Safe Area.
// Make it constrained to the edges of the safe area.
UILayoutGuide *guide = self.view.safeAreaLayoutGuide;
[NSLayoutConstraint activateConstraints:@[
[guide.leftAnchor constraintEqualToAnchor:bannerView.leftAnchor],
[guide.rightAnchor constraintEqualToAnchor:bannerView.rightAnchor],
[guide.bottomAnchor constraintEqualToAnchor:bannerView.bottomAnchor]
]];
}
- (void)positionBannerViewFullWidthAtBottomOfView:(UIView *_Nonnull)bannerView {
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeading
multiplier:1
constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeTrailing
multiplier:1
constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self.bottomLayoutGuide
attribute:NSLayoutAttributeTop
multiplier:1
constant:0]];
}
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-09-02 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-09-02 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eSmart Banners are responsive ad units that adjust their size to fit the width of the device's screen, spanning the full width in either portrait or landscape orientation.\u003c/p\u003e\n"],["\u003cp\u003eOn iPhones, Smart Banners have a height of 50 points in portrait and 32 points in landscape; on iPads, the height is consistently 90 points in both orientations.\u003c/p\u003e\n"],["\u003cp\u003eIt is recommended to use the newer adaptive banners instead of Smart Banners for better ad performance and user experience.\u003c/p\u003e\n"],["\u003cp\u003eFor full-width banners, especially with iOS 11 and later, constraints should be added to align the banner edges with the safe area edges for optimal display.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/admob/android/banner/smart \"View this page for the Android platform docs.\") [iOS](/admob/ios/banner/smart \"View this page for the iOS platform docs.\") [Unity](/admob/unity/banner/smart \"View this page for the Unity platform docs.\")\n\n\u003cbr /\u003e\n\n| Try the newer [adaptive banners](/admob/ios/banner/anchored-adaptive) instead.\n\nSmart Banners are ad units that render screen-width banner ads on any screen\nsize across different devices in either orientation. Smart Banners detect the\nwidth of the device in its current orientation and create the ad view that size.\n\nSmart Banners on iPhones have a height of 50 points in portrait and 32 points in\nlandscape. On iPads, height is 90 points in both portrait and landscape.\n\nWhen an image ad isn't large enough to take up the entire allotted space, the\nimage will be centered, and the space on either side will be filled in.\n\nTo use Smart Banners, just specify `kGADAdSizeSmartBannerPortrait`\n(for portait orientation) or `kGADAdSizeSmartBannerLandscape` (for landscape\norientation) for the ad size: \n\nSwift \n\n```swift\nlet bannerView = GADBannerView(adSize: kGADAdSizeSmartBannerPortrait)\n```\n\nObjective-C \n\n```objective-c\nGADBannerView *bannerView = [[GADBannerView alloc]\n initWithAdSize:kGADAdSizeSmartBannerPortrait];\n```\n\nSince the addition of the safe area for iOS 11, for full-width banners you\nshould also add constraints for the edges of the banner to the edges of the\nsafe area. Here is a code snippet showing how to do this: \n\nSwift \n\n```swift\nfunc addBannerViewToView(_ bannerView: GADBannerView) {\n bannerView.translatesAutoresizingMaskIntoConstraints = false\n view.addSubview(bannerView)\n if #available(iOS 11.0, *) {\n // In iOS 11, we need to constrain the view to the safe area.\n positionBannerViewFullWidthAtBottomOfSafeArea(bannerView)\n }\n else {\n // In lower iOS versions, safe area is not available so we use\n // bottom layout guide and view edges.\n positionBannerViewFullWidthAtBottomOfView(bannerView)\n }\n}\n\n// MARK: - view positioning\n@available (iOS 11, *)\nfunc positionBannerViewFullWidthAtBottomOfSafeArea(_ bannerView: UIView) {\n // Position the banner. Stick it to the bottom of the Safe Area.\n // Make it constrained to the edges of the safe area.\n let guide = view.safeAreaLayoutGuide\n NSLayoutConstraint.activate([\n guide.leftAnchor.constraint(equalTo: bannerView.leftAnchor),\n guide.rightAnchor.constraint(equalTo: bannerView.rightAnchor),\n guide.bottomAnchor.constraint(equalTo: bannerView.bottomAnchor)\n ])\n}\n\nfunc positionBannerViewFullWidthAtBottomOfView(_ bannerView: UIView) {\n view.addConstraint(NSLayoutConstraint(item: bannerView,\n attribute: .leading,\n relatedBy: .equal,\n toItem: view,\n attribute: .leading,\n multiplier: 1,\n constant: 0))\n view.addConstraint(NSLayoutConstraint(item: bannerView,\n attribute: .trailing,\n relatedBy: .equal,\n toItem: view,\n attribute: .trailing,\n multiplier: 1,\n constant: 0))\n view.addConstraint(NSLayoutConstraint(item: bannerView,\n attribute: .bottom,\n relatedBy: .equal,\n toItem: bottomLayoutGuide,\n attribute: .top,\n multiplier: 1,\n constant: 0))\n}\n```\n\nObjective-C \n\n```objective-c\n- (void)addBannerViewToView:(UIView *)bannerView {\n bannerView.translatesAutoresizingMaskIntoConstraints = NO;\n [self.view addSubview:bannerView];\n if (@available(ios 11.0, *)) {\n // In iOS 11, we need to constrain the view to the safe area.\n [self positionBannerViewFullWidthAtBottomOfSafeArea:bannerView];\n } else {\n // In lower iOS versions, safe area is not available so we use\n // bottom layout guide and view edges.\n [self positionBannerViewFullWidthAtBottomOfView:bannerView];\n }\n}\n\n#pragma mark - view positioning\n\n- (void)positionBannerViewFullWidthAtBottomOfSafeArea:(UIView *_Nonnull)bannerView NS_AVAILABLE_IOS(11.0) {\n // Position the banner. Stick it to the bottom of the Safe Area.\n // Make it constrained to the edges of the safe area.\n UILayoutGuide *guide = self.view.safeAreaLayoutGuide;\n\n [NSLayoutConstraint activateConstraints:@[\n [guide.leftAnchor constraintEqualToAnchor:bannerView.leftAnchor],\n [guide.rightAnchor constraintEqualToAnchor:bannerView.rightAnchor],\n [guide.bottomAnchor constraintEqualToAnchor:bannerView.bottomAnchor]\n ]];\n}\n\n- (void)positionBannerViewFullWidthAtBottomOfView:(UIView *_Nonnull)bannerView {\n [self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView\n attribute:NSLayoutAttributeLeading\n relatedBy:NSLayoutRelationEqual\n toItem:self.view\n attribute:NSLayoutAttributeLeading\n multiplier:1\n constant:0]];\n [self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView\n attribute:NSLayoutAttributeTrailing\n relatedBy:NSLayoutRelationEqual\n toItem:self.view\n attribute:NSLayoutAttributeTrailing\n multiplier:1\n constant:0]];\n [self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView\n attribute:NSLayoutAttributeBottom\n relatedBy:NSLayoutRelationEqual\n toItem:self.bottomLayoutGuide\n attribute:NSLayoutAttributeTop\n multiplier:1\n constant:0]];\n}\n```"]]