Allow Multiple Ad Sizes to Serve into a Banner Ad View

Banner ads with a fixed size may not get as much demand as you'd like. To open up a banner ad view to more demand, and hopefully more revenue, you can allow more than one ad size to serve.

Follow the instructions below to allow multiple ad sizes to serve into your banner ad views.

iOS

To allow multiple ad sizes to serve into a banner ad view on iOS, use the setAdSizesmethod:

- (void)setAdSizes:(NSArray<NSValue *> *)adSizes

As shown in the example below, the sizes array needs to be an NSArray of NSValue objects wrapping CGSize structs, as described in the NSValue documentation:

// Create the banner ad view and add it as a subview
ANBannerAdView *banner = [ANBannerAdView adViewWithFrame:rect placementId:@"1326299" adSize:size];
banner.rootViewController = self;

// Fill in the ad sizes array.
CGSize size1 = CGSizeMake(300,  50);
CGSize size2 = CGSizeMake(300, 250);
NSArray *sizes = @[[NSValue valueWithCGSize:size1], [NSValue valueWithCGSize:size2]];

// Pass the ad sizes array to the banner ad view.
[banner setAdSizes:sizes];

[self.view addSubview:banner];

// Load an ad!
[banner loadAd];

Android

To allow multiple ad sizes to serve into a banner ad view on Android, use the following methods on BannerAdView:

Example:

// Create the AdView and set its placement ID.
BannerAdView bav = new BannerAdView(this);
bav.setPlacementID("1326299");

// Build up the ad sizes array.
ArrayList<AdSize> sizes = new ArrayList<AdSize>();
sizes.add(new AdSize(300,  50));
sizes.add(new AdSize(300, 250));

// Pass the ad sizes array to the banner ad view.
bav.setAdSizes(sizes);

// Add the AdView to our layout.
FrameLayout layout = (FrameLayout)findViewById(android.R.id.content);
layout.addView(bav);

// Load an ad!
bav.loadAd();

Related Topics