固定大小橫幅廣告

Google Mobile Ads SDK 支援自動調整廣告大小, 橫幅廣告不符合需求

下表列出標準橫幅廣告大小。

大小,以 dp 為單位 (寬 x 高) 說明 可用性 AdSize 常數
320x50 橫幅廣告 手機和平板電腦 GADAdSizeBanner
320x100 大型橫幅 手機和平板電腦 GADAdSizeLargeBanner
300x250 IAB 中矩形廣告 手機和平板電腦 GADAdSizeMediumRectangle
468x60 IAB 完整大小橫幅廣告 平板電腦 GADAdSizeFullBanner
728x90 IAB 超級橫幅廣告 平板電腦 GADAdSizeLeaderboard

如要定義自訂橫幅大小,請使用 GADAdSizeFromCGSize 設定大小:

Swift

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

Objective-C

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

固定大小的橫幅廣告範例

快速 Objective-C

自訂廣告大小

除了標準廣告單元,Google Ad Manager 也可讓您放送任何大小的廣告 應用程式內為廣告請求定義的廣告大小 (寬度、高度) 應該與廣告檢視畫面的維度 (GAMBannerView) 一致 應用程式。如要設定自訂大小,請使用 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];

多種廣告大小

Ad Manager 可讓您指定多個符合放送資格的廣告大小 放入 GAMBannerView 中。您必須先完成三個步驟 功能:

  1. 在 Ad Manager 使用者介面中,建立一個委刊項並指定同一個廣告單元 以及與不同大小的廣告素材建立關聯

  2. 在應用程式中,在 GAMBannerView 上設定 validAdSizes 屬性:

    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. 執行 GADAdSizeDelegate 方法,偵測廣告大小變化。

    Swift

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

    Objective-C

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

    請記得在請求廣告之前,設定委派。

    Swift

    bannerView.adSizeDelegate = self
    

    Objective-C

    self.bannerView.adSizeDelegate = self;
    

多種廣告大小範例

快速 Objective-C