Richard
Richard

Reputation: 139

Change the adsize in GADBannerView

I integrated the admob.My App supports both Portrait and Landscape modes.In portrait mode,it works perfectly but landscape mode not changed the adsize.In Landscape mode,the bannerview ad contains left and right space.

how to change the adsize?

Kindly help me.

Upvotes: 3

Views: 3782

Answers (5)

Mahesh Vemula
Mahesh Vemula

Reputation: 1

For Landscape Ipad and Iphone

[bannerView setAdSize:GADAdSizeFullWidthLandscapeWithHeight(90)];

[bannerView setAdSize:GADAdSizeFullWidthLandscapeWithHeight(50)];

For Portrait Ipad and Iphone

[bannerView setAdSize:GADAdSizeFullWidthPortraitWithHeight(90)];

[bannerView setAdSize:GADAdSizeFullWidthPortraitWithHeight(50)];

Upvotes: 0

MikeJ
MikeJ

Reputation: 2437

Swift answer to compliment the obj-c one.

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    if UIDevice.currentDevice().orientation.isLandscape.boolValue {
        self.bannerView.adSize = kGADAdSizeSmartBannerLandscape;
    } else {
        self.bannerView.adSize = kGADAdSizeSmartBannerPortrait;
    }
}

Upvotes: 2

Vaiden
Vaiden

Reputation: 16132

My solution was to simply scale the banner view, as everything else seems to fail:

https://stackoverflow.com/a/32203739/606351

Upvotes: 1

Eric Leichtenschlag
Eric Leichtenschlag

Reputation: 8931

If you're looking for full-width ads, use the smart banner format:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInt
                               duration:(NSTimeInterval)duration {
  if (UIInterfaceOrientationIsLandscape(toInt)) {
    self.adBanner.adSize = kGADAdSizeSmartBannerLandscape;
  } else {
    self.adBanner.adSize = kGADAdSizeSmartBannerPortrait;
  }
}

Changing the ad size like this will automatically trigger a new request for you using the new size.

Upvotes: 2

Saad
Saad

Reputation: 8947

simply set GADBannerView frame's width to self.view.frame.size.width in autroate deleagate methods. Like this

- (BOOL)shouldAutorotate 
{
   CGRect tframe = _adView.frame;
   tframe.size.width = self.view.frame.size.width;
   _adView.frame = tframe;
}

Upvotes: 0

Related Questions