Anúncios de banner com tamanho fixo

O SDK dos anúncios para dispositivos móveis do Google é compatível com tamanhos fixos de anúncio nas situações em que os anúncios de banner adaptativo não atendem às suas necessidades.

A tabela a seguir lista os tamanhos padrão de banner.

Tamanho em dp (L x A) Descrição Disponibilidade Constante "AdSize"
320 x 50 Banner Smartphones e tablets GADAdSizeBanner
320 x 100 Banner grande Smartphones e tablets GADAdSizeLargeBanner
300 x 250 Retângulo IAB médio Smartphones e tablets GADAdSizeMediumRectangle
468 x 60 Banner do IAB em tamanho real Tablets GADAdSizeFullBanner
728 x 90 Cabeçalho IAB Tablets GADAdSizeLeaderboard

Para definir um tamanho de banner personalizado, use GADAdSizeFromCGSize:

Swift

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

Objective-C

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

Exemplo de anúncios de banner de tamanho fixo

Swift Objective-C

Tamanho de anúncio personalizado

Além dos blocos de anúncios padrão, o Google Ad Manager permite veicular blocos de anúncios de qualquer tamanho em um app. O tamanho do anúncio (largura e altura) definido para uma solicitação de anúncio precisa corresponder às dimensões da visualização de anúncio (GAMBannerView) exibida no app. Para definir um tamanho personalizado, 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];

Vários tamanhos de anúncio

O Ad Manager permite especificar vários tamanhos de anúncio que podem ser qualificados para veiculação em uma GAMBannerView. Há três etapas necessárias para usar esse recurso:

  1. Na interface do Ad Manager, crie um item de linha segmentando o mesmo bloco de anúncios que está associado a criativos de tamanhos diferentes.

  2. No seu app, defina a propriedade validAdSizes em 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. Implemente o método GADAdSizeDelegate para detectar uma mudança no tamanho do anúncio.

    Swift

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

    Objective-C

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

    Lembre-se de definir o delegado antes de solicitar um anúncio.

    Swift

    bannerView.adSizeDelegate = self
    

    Objective-C

    self.bannerView.adSizeDelegate = self;
    

Exemplo com vários tamanhos de anúncio

Swift Objective-C