El SDK de anuncios de Google para dispositivos móviles admite tamaños de anuncios fijos en las situaciones en que los anuncios de banner adaptable no satisfacen tus necesidades.
En la siguiente tabla, se enumeran los tamaños de banner estándar.
Tamaño en dp (ancho × alto) | Descripción | Disponibilidad | Constante de AdSize |
---|---|---|---|
320 × 50 | Banner | Teléfonos y tablets | GADAdSizeBanner |
320 × 100 | Banner grande | Teléfonos y tablets | GADAdSizeLargeBanner |
300 × 250 | Rectángulo mediano de IAB | Teléfonos y tablets | GADAdSizeMediumRectangle |
468 × 60 | Banner de tamaño completo de IAB | Tablets | GADAdSizeFullBanner |
728 × 90 | Leaderboard de IAB | Tablets | GADAdSizeLeaderboard |
Para definir un tamaño de banner personalizado, establécelo con GADAdSizeFromCGSize
:
Swift
let adSize = adSizeFor(cgSize: CGSize(width: 250, height: 250))
Objective-C
GADAdSize size = GADAdSizeFromCGSize(CGSizeMake(250, 250));
Ejemplo de anuncios de banner de tamaño fijo
Tamaño de anuncio personalizado
Además de las unidades de anuncios estándar, Google Ad Manager te permite publicar unidades de anuncios de cualquier tamaño en una app. El tamaño del anuncio (ancho y alto) definido para una solicitud de anuncio debe coincidir con las dimensiones de la vista del anuncio (GAMBannerView
) que se muestra en la app. Para establecer un tamaño personalizado, usa 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];
Múltiples tamaños de anuncios
Ad Manager te permite especificar múltiples tamaños de anuncios que podrían ser aptos para publicarse en una clase GAMBannerView
. Para usar esta función, debes seguir estos tres pasos:
En la IU de Ad Manager, crea una línea de pedido segmentada para la misma unidad de anuncios que está asociada a creatividades de diferentes tamaños.
En tu app, establece la propiedad
validAdSizes
enGAMBannerView
: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))) ];
Implementa el método
GADAdSizeDelegate
para detectar un cambio en el tamaño del anuncio.Swift
public func bannerView(_ bannerView: BannerView, willChangeAdSizeTo size: AdSize)
Objective-C
- (void)bannerView:(GAMBannerView *)view willChangeAdSizeTo:(GADAdSize)size;
Recuerda establecer el delegado antes de realizar la solicitud de un anuncio.
Swift
bannerView.adSizeDelegate = self
Objective-C
self.bannerView.adSizeDelegate = self;