Fixed size banner ads

The Google Mobile Ads SDK supports fixed ad sizes for situations where adaptive banners ads don't meet your needs.

The following table lists the standard banner sizes.

Size in dp (WxH) Description Availability AdSize constant
320x50 Banner Phones and tablets GADAdSizeBanner
320x100 Large banner Phones and tablets GADAdSizeLargeBanner
300x250 IAB medium rectangle Phones and tablets GADAdSizeMediumRectangle
468x60 IAB full-size banner Tablets GADAdSizeFullBanner
728x90 IAB leaderboard Tablets GADAdSizeLeaderboard

To define a custom banner size, set your size using GADAdSizeFromCGSize:

Swift

let adSize = GADAdSizeFromCGSize(CGSize(width: 250, height: 250))

Objective-C

GADAdSize size = GADAdSizeFromCGSize(CGSizeMake(250, 250));

Fixed size banner ads example

Swift Objective-C

Custom ad size

In addition to the standard ad units, Google Ad Manager lets you serve any sized ad unit into an app. The ad size (width, height) defined for an ad request should match the dimensions of the ad view (GAMBannerView) displayed on the app. To set a custom size, use GADAdSizeFromCGSize.

Swift

// Define custom GADAdSize of 250x250 for GAMBannerView.
let customAdSize = GADAdSizeFromCGSize(CGSize(width: 250, height: 250))
bannerView = GAMBannerView(adSize: customAdSize)

Objective-C

// Define custom GADAdSize of 250x250 for GAMBannerView
GADAdSize customAdSize = GADAdSizeFromCGSize(CGSizeMake(250, 250));
self.bannerView = [[GAMBannerView alloc] initWithAdSize:customAdSize];

Multiple ad sizes

Ad Manager lets you specify multiple ad sizes which could be eligible to serve into a GAMBannerView. There are three steps needed in order to use this feature:

  1. In the Ad Manager UI, create a line item targeting the same ad unit that is associated with different size creatives.

  2. In your app, set the validAdSizes property on GAMBannerView:

    Swift

    // Define an optional array of GADAdSize to specify all valid sizes that are appropriate
    // for this slot. Never create your own GADAdSize directly. Use one of the
    // predefined standard ad sizes (such as GADAdSizeBanner), or create one using
    // the GADAdSizeFromCGSize method.
    //
    // Note: Ensure that the allocated GAMBannerView is defined with an ad size. Also note
    // that all desired sizes should be included in the validAdSizes array.
    bannerView.validAdSizes = [NSValueFromGADAdSize(GADAdSizeBanner),
        NSValueFromGADAdSize(GADAdSizeMediumRectangle),
        NSValueFromGADAdSize(GADAdSizeFromCGSize(CGSize(width: 120, height: 20)))]
    

    Objective-C

    // Define an optional array of GADAdSize to specify all valid sizes that are appropriate
    // for this slot. Never create your own GADAdSize directly. Use one of the
    // predefined standard ad sizes (such as GADAdSizeBanner), or create one using
    // the GADAdSizeFromCGSize method.
    //
    // Note: Ensure that the allocated GAMBannerView is defined with an ad size. Also note
    // that all desired sizes should be included in the validAdSizes array.
    self.bannerView.validAdSizes = @[
        NSValueFromGADAdSize(GADAdSizeBanner),
        NSValueFromGADAdSize(GADAdSizeMediumRectangle),
        NSValueFromGADAdSize(GADAdSizeFromCGSize(CGSizeMake(120, 20)))
    ];
    
  3. Implement the GADAdSizeDelegate method to detect an ad size change.

    Swift

    public func bannerView(_ bannerView: GADBannerView, willChangeAdSizeTo size: GADAdSize)
    

    Objective-C

    - (void)bannerView:(GAMBannerView *)view willChangeAdSizeTo:(GADAdSize)size;
    

    Remember to set the delegate before making the request for an ad.

    Swift

    bannerView.adSizeDelegate = self
    

    Objective-C

    self.bannerView.adSizeDelegate = self;
    

Multiple ad sizes example

Swift Objective-C