Liam Stockhomme
Liam Stockhomme

Reputation: 523

How to center AdMob advertisement on iPad?

I'm just testing out the AdMob code I've put into my application and I can't figure out why the advertisement is not centring on the iPad. On the iPhone it perfectly centres itself.

This is the code:

    //google ad
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        googleBanner_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeLeaderboard origin:CGPointMake(0, 0)];
    }else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        googleBanner_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner origin:CGPointMake(0, 0)];
    }
    //googleBanner_.adUnitID = @"pub";
    googleBanner_.rootViewController = self;
    [self.view addSubview:googleBanner_];

    [googleBanner_ loadRequest:[GADRequest request]];

}

- (BOOL)prefersStatusBarHidden {
    return YES;
}

I had assumed that I could change the x-coordinate on the iPad ad position but that simply put half of it off the screen.

(this is what I did)

googleBanner_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeLeaderboard origin:CGPointMake(384, 0)]; //768/2 = 384 

Any ideas as to why this is happening? What can I do to properly center the advertisement on the iPad? NOTE: kGADAdSizeLeaderboard dimensions = 728 x 90

Upvotes: 0

Views: 895

Answers (1)

Liam Stockhomme
Liam Stockhomme

Reputation: 523

Fixed it. For those that encounter the same problem, simply take the x-dimension of the kGADAdSizeLeaderboard which is 728, and subtract it from the total width which is 768, which gives you 40. Then divide 40 by two to have it even on both sides, giving you 20. Then simply set the x-coordinate in the origin to 20, placing the ad in the middle of the screen.

Code:

googleBanner_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeLeaderboard origin:CGPointMake(20, 0)];

Upvotes: 1

Related Questions