O Google Mobile Ads SDK aceita tamanhos fixos de anúncios para situações em que os anúncios de banner adaptativos não atendem às suas demandas.
A tabela a seguir lista os tamanhos de banner padrão.
| Tamanho em dp (L x A) | Descrição | Disponibilidade | Constante AdSize |
|---|---|---|---|
| 320 x 50 | Banner | Celulares e tablets | GADAdSizeBanner |
| 320 x 100 | Banner grande | Celulares e tablets | GADAdSizeLargeBanner |
| 300 x 250 | Retângulo médio IAB | Celulares e tablets | GADAdSizeMediumRectangle |
| 468 x 60 | Banner em tamanho real IAB | Tablets | GADAdSizeFullBanner |
| 728 x 90 | Cabeçalho IAB | Tablets | GADAdSizeLeaderboard |
Para definir um tamanho personalizado, use GADAdSizeFromCGSize:
Swift
let adSize = adSizeFor(cgSize: CGSize(width: 250, height: 250))
Objective-C
GADAdSize size = GADAdSizeFromCGSize(CGSizeMake(250, 250));
Defina um tamanho de anúncio menor ou igual ao tamanho da tela do dispositivo.
Para determinar o tamanho máximo da tela no iOS 26 e versões mais recentes, use a propriedade
UIWindowScene.effectiveGeometry.coordinateSpace
. No iOS 18 e versões anteriores, use a propriedade
UIWindowScene.coordinateSpace
.
Para mais detalhes sobre as restrições de tamanho, consulte
Resolver problemas de impressões não preenchidas no Ad Manager.
Exemplo de anúncios de banner de tamanho fixo
Tamanho de anúncio personalizado
Além dos blocos de anúncios padrão, o Google Ad Manager permite veicular blocos de qualquer tamanho
em um app. O tamanho do anúncio (largura, altura) definido para uma solicitação
precisa corresponder às dimensões da visualização de anúncio (GAMBannerView) mostrada no
app. Para definir um tamanho personalizado, use GADAdSizeFromCGSize.
Swift
// Define custom GADAdSize of 250x250 for GAMBannerView.
let customAdSize = adSizeFor(cgSize: 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 veiculados
em um GAMBannerView. Para usar esse recurso, é necessário seguir três etapas:
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.
No app, defina a propriedade
validAdSizesemGAMBannerView: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(AdSizeBanner), NSValueFromGADAdSize(AdSizeMediumRectangle), NSValueFromGADAdSize(adSizeFor(cgSize: 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))) ];Implemente o método
GADAdSizeDelegatepara detectar uma alteração no tamanho do anúncio.Swift
public func bannerView(_ bannerView: BannerView, willChangeAdSizeTo size: AdSize)Objective-C
- (void)bannerView:(GAMBannerView *)view willChangeAdSizeTo:(GADAdSize)size;Lembre-se de definir o delegado antes de fazer a solicitação de um anúncio.
Swift
bannerView.adSizeDelegate = selfObjective-C
self.bannerView.adSizeDelegate = self;