تنظیمات سبک بومی Google Ad Manager را قادر میسازد تا رندر تبلیغات بومی شما را بر اساس سبکهای بومی که در محصول مشخص میکنید انجام دهد. ابتدا اندازه و هدف را مشخص کنید. سپس HTML، CSS و جاوا اسکریپت را اضافه کنید تا تبلیغاتی را تعریف کنید که واکنشگرا هستند و نمایش با کیفیتی را در تمام صفحه ها ایجاد کنند. شما نیازی به انجام هیچ یک از رندر ندارید. Ad Manager به طور خودکار سبک بومی مناسب را برای مقصد اعمال می کند. سبک های بومی درست مانند تبلیغات بنری با استفاده از GAMBannerView پیاده سازی می شوند. آنها را می توان با اندازه تبلیغات ثابت که از قبل تعیین شده است، یا اندازه تبلیغ سیال تعیین شده در زمان اجرا استفاده کرد.
پیش نیازها
Google Mobile Ads SDK نسخه 7.14.0 یا بالاتر
این راهنما اطلاعاتی در مورد Google Mobile Ads SDK در نظر گرفته است. اگر قبلاً این کار را نکردهاید، راهنمای شروع ما را در نظر بگیرید.
اندازه ثابت
سبک های بومی با اندازه ثابت به شما امکان می دهد عرض و ارتفاع تبلیغات بومی را کنترل کنید. برای تنظیم اندازه ثابت، مراحل زیر را دنبال کنید:
یک آیتم خط در رابط کاربری Ad Manager ایجاد کنید و یکی از اندازه های از پیش تعریف شده را از قسمت کشویی فیلد Size انتخاب کنید.
در Interface Builder، عرض و ارتفاع GAMBannerView را طوری تنظیم کنید که با اندازه از پیش تعریف شده ای که در مرحله 1 انتخاب کرده اید مطابقت داشته باشد. می توانید لیستی از اندازه ها و ثابت های GADAdSize مربوط به آنها را در بخش اندازه بنر مشاهده کنید.
پیادهسازی سبکهای بومی با اندازه ثابت به سادگی پیروی از دستورالعملها در اولین درخواست بنر شما است، اما انعطافپذیری و کنترل بر روی HTML، CSS، و جاوا اسکریپت را به دست میآورید تا به تبلیغات بنر خود ظاهر و احساسی طبیعی بدهید که در برنامه شما طبیعی است.
اندازه مایع
در برخی موارد، اندازه ثابت ممکن است منطقی نباشد. به عنوان مثال، ممکن است بخواهید عرض تبلیغ با محتوای برنامه شما مطابقت داشته باشد، اما به ارتفاع آن نیاز داشته باشید تا به صورت پویا و متناسب با محتوای تبلیغ تنظیم شود. برای رسیدگی به این مورد، میتوانید Fluid بهعنوان اندازه تبلیغ در رابط کاربری Ad Manager تعیین کنید، که نشان میدهد اندازه آگهی در زمان اجرا در برنامه تعیین میشود. SDK یک ثابت GADAdSize ویژه، kGADAdSizeFluid را برای رسیدگی به این مورد فراهم می کند. ارتفاع اندازه تبلیغ سیال به صورت پویا بر اساس عرض تعریف شده ناشر تعیین میشود و به GAMBannerView اجازه میدهد تا ارتفاع خود را مطابق با ارتفاع آگهی تنظیم کند.
درخواست مایعات
برخلاف سایر قالبهای تبلیغاتی، اندازه تبلیغ kGADAdSizeFluid دارای عرض از پیش تعریفشده نیست، بنابراین مطمئن شوید که عرض فریم بنر را در کد خود یا در Interface Builder به صراحت تنظیم کنید. اگر عرض مشخص نشده باشد، SDK به طور پیش فرض ارتفاع بنر را بر اساس عرض کامل دستگاه تنظیم می کند.
اگر یک درخواست چند اندازه ای که شامل kGADAdSizeFluid باشد، ارسال می کنید، آگهی بازگردانده شده همیشه در یک ظرف مایع قرار می گیرد و مانند یک تبلیغ سیال رفتار می کند. در صورتی که یک خلاقیت غیر روان در این محفظه سیال برگردانده شود، SDK آگهی را در کانتینر متمرکز میکند تا مجبور نباشید هر بار که تبلیغ جدیدی برگردانده میشود، محدودیت عرض را تغییر دهید.
پیاده سازی برای ایجاد یک اندازه تک و یک درخواست سیال چند اندازه بسیار مشابه است. تنها تفاوت در درخواست چند اندازه است، شما ویژگی validAdSizes را برای تعیین اندازه های تبلیغاتی که برای درخواست تبلیغ معتبر هستند تنظیم می کنید:
varbannerView:AdManagerBannerView!overridefuncviewDidLoad(){super.viewDidLoad()// Create the GAMBannerView and set its width to a width that makes sense for your// app. In this example, the width is set to the width of the UIViewController's// root view.bannerView=AdManagerBannerView(adSize:AdSizeFluid)varframeRect=bannerView.frameframeRect.size.width=view.bounds.widthbannerView.frame=frameRect// Uncomment this code for a multisize fluid request.// bannerView.validAdSizes = [nsValue(for: AdSizeFluid), nsValue(for: AdSizeBanner)]bannerView.adUnitID="YOUR_AD_UNIT_ID"bannerView.rootViewController=self// Make the ad request.bannerView.load(AdManagerRequest())}
هدف-C
GAMBannerView*_bannerView;-(void)viewDidLoad{[superviewDidLoad];// Create the GAMBannerView and set its width to a width that makes sense for your// app. In this example, the width is set to the width of the UIViewController's// root view._bannerView=[[GAMBannerViewalloc]initWithAdSize:kGADAdSizeFluid];CGRectframeRect=_bannerView.frame;frameRect.size.width=CGRectGetWidth(self.view.bounds);_bannerView.frame=frameRect;// Uncomment this code for a multisize fluid request.// _bannerView.validAdSizes = @[ NSValueFromGADAdSize(kGADAdSizeFluid),// NSValueFromGADAdSize(kGADAdSizeBanner) ];_bannerView.adUnitID=@"YOUR_AD_UNIT_ID";_bannerView.rootViewController=self;// Make the ad request.[_bannerViewloadRequest:[GAMRequestrequest]];}
برای مشاهده نمونهای از اجرای اندازه تبلیغ Ad Manager Fluid، برنامه آزمایشی iOS API را در Swift یا Objective-C دانلود کنید.
ممکن است بخواهید قبل از تغییر اندازه یک بنر، ارتفاع آن را بدانید. پاسخ تماس adView:willChangeAdSizeTo: نماینده خود را قبل از تغییر نمای بنر به GADAdSize جدید مطلع می کند. برای اینکه قبل از تغییر نمای بنر به اندازه آگهی جدید مطلع شوید، کلاس شما باید با پروتکل GADAdSizeDelegate مطابقت داشته باشد.
در اینجا یک نمونه پیاده سازی از adView:willChangeAdSizeTo: callback آورده شده است که نحوه دریافت عرض و ارتفاع جدید بنر را نشان می دهد:
سویفت
// To be notified before the banner's ad size changes, your view controller class must// conform to the GADAdSizeDelegate protocol.bannerView.adSizeDelegate=self// MARK: - GADAdSizeDelegatefuncadView(_bannerView:BannerView,willChangeAdSizeToadSize:AdSize){letheight=adSize.size.heightletwidth=adSize.size.width}
هدف-C
// To be notified before the banner's ad size changes, your view controller class must// conform to the GADAdSizeDelegate protocol._bannerView.adSizeDelegate=self;
#pragmamark-GADAdSizeDelegate-(void)adView:(GADBannerView*)bannerViewwillChangeAdSizeTo:(GADAdSize)adSize{CGFloatheight=adSize.size.height;CGFloatwidth=adSize.size.width;}
تاریخ آخرین بهروزرسانی 2025-08-27 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-27 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eNative Styles in Google Ad Manager allow you to customize the look and feel of native ads using HTML, CSS, and JavaScript, rendering them seamlessly within your app.\u003c/p\u003e\n"],["\u003cp\u003eYou can define fixed-size native ads by specifying their dimensions in Ad Manager and your app's layout, similar to implementing banner ads.\u003c/p\u003e\n"],["\u003cp\u003eFluid-size native ads adjust their height dynamically based on content and available width, requiring you to set the desired width in your app's code.\u003c/p\u003e\n"],["\u003cp\u003eTo get notified before a banner's size changes (especially useful for fluid ads), implement the \u003ccode\u003eGADAdSizeDelegate\u003c/code\u003e protocol and its \u003ccode\u003eadView:willChangeAdSizeTo:\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eYou can download the iOS API Demo app for example implementations of Native Styles, including fluid ad sizes.\u003c/p\u003e\n"]]],["Native styles in Google Ad Manager utilize HTML, CSS, and JavaScript for ad rendering. Ad size can be fixed by setting predefined dimensions in the UI and `GAMBannerView`, or fluid, adjusting dynamically at runtime with `kGADAdSizeFluid`. Fluid ads require setting the banner's frame width. Multisize requests can include fluid and other ad sizes. `GADAdSizeDelegate` enables notification before banner size changes, providing access to the new width and height.\n"],null,["# Native Styles\n\nSelect platform: [Android](/ad-manager/mobile-ads-sdk/android/native/styles \"View this page for the Android platform docs.\") [iOS](/ad-manager/mobile-ads-sdk/ios/native/styles \"View this page for the iOS platform docs.\") [Flutter](/ad-manager/mobile-ads-sdk/flutter/native/styles \"View this page for the Flutter platform docs.\")\n\n\u003cbr /\u003e\n\n| **Note:** Native Styles use HTML and CSS that you configure in Google Ad Manager. If you're looking to render your own in-app ads using native objects, please see [Native Advanced](/ad-manager/mobile-ads-sdk/ios/native/advanced).\n\n[Native style settings](//support.google.com/admanager/answer/6366914)\nenable Google Ad Manager to handle the rendering of your native ads based on native\nstyles you specify within the product. First, specify size and targeting.\nThen add HTML, CSS, and JavaScript to define ads that are responsive\nand produce a quality display across all screens. You don't need to do\nany of the rendering; Ad Manager automatically applies the right native style\nfor the destination. Native styles are implemented just like banner ads,\nusing a `GAMBannerView`. They can be used with a fixed ad\nsize determined ahead of time, or a fluid ad size determined at runtime.\n\nPrerequisites\n-------------\n\n- Google Mobile Ads SDK version 7.14.0 or higher\n\nThis guide assumes some working knowledge of the Google Mobile Ads SDK.\nIf you haven't already done so, consider running through our\n[Get Started](/ad-manager/mobile-ads-sdk/ios/quick-start) guide.\n\nFixed size\n----------\n\nNative styles with a fixed size allow you to control the width and height\nof the native ad. To set a fixed size, follow these steps:\n\n1. Create a line item in the Ad Manager UI and select one of the\n predefined sizes from the `Size` field dropdown.\n\n2. In Interface Builder, set the width and height of the `GAMBannerView`\n to match the predefined size you selected in step 1. You can see a\n list of sizes and their corresponding `GADAdSize` constants in the [Banner\n size](/ad-manager/mobile-ads-sdk/ios/banner#banner_size)\n section.\n\nImplementing native styles with a fixed size is as simple as following\nthe instructions in [Your first banner\nrequest](/ad-manager/mobile-ads-sdk/ios/quick-start#your_first_banner_request),\nbut you gain the flexibility and control over the HTML, CSS, and JavaScript\nto give your banner ad a native look and feel that's natural in your app.\n\nFluid size\n----------\n\nIn some cases, a fixed size may not make sense. For example, you may\nwant the width of the ad to match your app's content, but need its height\nto dynamically adjust to fit the ad's content. To handle this case,\nyou can specify `Fluid` as the ad size in the Ad Manager UI, which\ndesignates that the size of the ad is determined at runtime in the app.\nThe SDK provides a special `GADAdSize` constant,\n[`kGADAdSizeFluid`](/ad-manager/mobile-ads-sdk/ios/api/reference/Constants#/c:@kGADAdSizeFluid),\nto handle this case. The fluid ad size height is dynamically determined\nbased on the publisher defined width, allowing the\n[`GAMBannerView`](/ad-manager/mobile-ads-sdk/ios/api/reference/Classes/GAMBannerView),\nto adjust its height to match that of the creative.\n\n### Fluid request\n\nUnlike other ad formats, the `kGADAdSizeFluid` ad size does not have\na predefined width, so make sure to explicitly set the banner's frame\nwidth in your code or in Interface Builder. If a width is not specified,\nthe SDK by default sets the height of the banner based on the full\nwidth of the device.\n\nIf you make a multisize request that includes `kGADAdSizeFluid`,\nthe ad returned is always placed inside a fluid container and\nbehave like a fluid ad. In the event that a non-fluid creative is\nreturned in this fluid container, the SDK centers the ad in the\ncontainer so that you don't have to modify the width constraint\neach time a new ad is returned.\n\nThe implementation for making a single size and a multisize fluid\nrequest is very similar; the only difference is for a multisize\nrequest, you set the `validAdSizes` property to specify the ad\nsizes that are valid for the ad request: \n\n### Swift\n\n bannerView.validAdSizes = [nsValue(for: AdSizeFluid), nsValue(for: AdSizeBanner)]\n\n### Objective-C\n\n _bannerView.validAdSizes = @[ NSValueFromGADAdSize(kGADAdSizeFluid),\n NSValueFromGADAdSize(kGADAdSizeBanner) ];\n\nHere's what the full implementation looks like in code: \n\n### Swift\n\n var bannerView: AdManagerBannerView!\n\n override func viewDidLoad() {\n super.viewDidLoad()\n // Create the GAMBannerView and set its width to a width that makes sense for your\n // app. In this example, the width is set to the width of the UIViewController's\n // root view.\n bannerView = AdManagerBannerView(adSize: AdSizeFluid)\n var frameRect = bannerView.frame\n frameRect.size.width = view.bounds.width\n bannerView.frame = frameRect\n\n // Uncomment this code for a multisize fluid request.\n // bannerView.validAdSizes = [nsValue(for: AdSizeFluid), nsValue(for: AdSizeBanner)]\n\n bannerView.adUnitID = \"YOUR_AD_UNIT_ID\"\n bannerView.rootViewController = self\n\n // Make the ad request.\n bannerView.load(AdManagerRequest())\n }\n\n### Objective-C\n\n GAMBannerView *_bannerView;\n\n - (void)viewDidLoad {\n [super viewDidLoad];\n // Create the GAMBannerView and set its width to a width that makes sense for your\n // app. In this example, the width is set to the width of the UIViewController's\n // root view.\n _bannerView = [[GAMBannerView alloc] initWithAdSize:kGADAdSizeFluid];\n CGRect frameRect = _bannerView.frame;\n frameRect.size.width = CGRectGetWidth(self.view.bounds);\n _bannerView.frame = frameRect;\n\n // Uncomment this code for a multisize fluid request.\n // _bannerView.validAdSizes = @[ NSValueFromGADAdSize(kGADAdSizeFluid),\n // NSValueFromGADAdSize(kGADAdSizeBanner) ];\n\n _bannerView.adUnitID = @\"YOUR_AD_UNIT_ID\";\n _bannerView.rootViewController = self;\n\n // Make the ad request.\n [_bannerView loadRequest:[GAMRequest request]];\n }\n\nTo see an example implementation of the Ad Manager Fluid ad size,\ndownload the iOS API Demo app in Swift or Objective-C.\n\n[Download API Demo](//github.com/googleads/googleads-mobile-ios-examples/releases/latest)\n\nGADAdSizeDelegate protocol\n--------------------------\n\nYou may want to know the height of a banner before its ad size changes.\nThe `adView:willChangeAdSizeTo:` callback notifies its delegate before\nthe banner view changes to the new `GADAdSize`. To be notified before\nthe banner view changes to the new ad size, your class must conform to\nthe `GADAdSizeDelegate` protocol.\n\nHere's a sample implementation of the `adView:willChangeAdSizeTo:`\ncallback that shows how to get the new width and height of the banner: \n\n### Swift\n\n // To be notified before the banner's ad size changes, your view controller class must\n // conform to the GADAdSizeDelegate protocol.\n bannerView.adSizeDelegate = self\n\n // MARK: - GADAdSizeDelegate\n\n func adView(_ bannerView: BannerView, willChangeAdSizeTo adSize: AdSize) {\n let height = adSize.size.height\n let width = adSize.size.width\n }\n\n### Objective-C\n\n // To be notified before the banner's ad size changes, your view controller class must\n // conform to the GADAdSizeDelegate protocol.\n _bannerView.adSizeDelegate = self;\n\n #pragma mark - GADAdSizeDelegate\n\n - (void)adView:(GADBannerView *)bannerView willChangeAdSizeTo:(GADAdSize)adSize {\n CGFloat height = adSize.size.height;\n CGFloat width = adSize.size.width;\n }"]]