Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place admob banner at bottom of screen in iOS retina and non retina

I've built a phonegap app and want to add an Admob banner to it. I have the banner working at the bottom of the screen in iOS6 simulator but when I test it on a retina device the banner will be way off of the bottom like it's still trying to size the screen for a non retina display. Here is my current code in viewDidLoad:

// Initialize the banner at the bottom of the screen.
CGPoint origin = CGPointMake(0.0,
                             self.view.frame.size.height -
                             CGSizeFromGADAdSize(kGADAdSizeBanner).height);

// Use predefined GADAdSize constants to define the GADBannerView.
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
                                             origin:origin];

// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = @"xxxxxxxxxxxx";

// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];

// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
like image 629
Brian Reeves Avatar asked Jan 28 '13 14:01

Brian Reeves


3 Answers

You can try this,

bannerView_ = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height-GAD_SIZE_320x50.height, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)];
like image 65
Yannis Avatar answered Oct 23 '22 16:10

Yannis


I solved this by moving the above code from viewDidLoad to webViewDidFinishLoad.

like image 42
Brian Reeves Avatar answered Oct 23 '22 15:10

Brian Reeves


I used this code to count for NavigationBar and Status Bar:

CGPoint origin = CGPointMake(0.0,
                             self.view.frame.size.height -
                             CGSizeFromGADAdSize(kGADAdSizeBanner).height -
                             self.navigationController.navigationBar.frame.size.height -
                             20 /* status bar */);
like image 1
Roozbeh Zabihollahi Avatar answered Oct 23 '22 15:10

Roozbeh Zabihollahi