user2872856
user2872856

Reputation: 2051

How do I position an Admob Smart Banner?

I created a 320x50 banner ad using this code:

var bannerView = GADBannerView(frame:CGRectMake(0, 20, 320, 50))

The ad should have y-position of 20 to leave a space for the status bar. Now, I would like to change to using a Smart Banner. So I changed my code to:

let bannerView = GADBannerView(adSize: kGADAdSizeSmartBannerPortrait)

Obviously the above code covers the status bar. I have no idea on how to make the Smart Banner appear at a y-position of 20.

Upvotes: 2

Views: 1834

Answers (3)

Daniel Storm
Daniel Storm

Reputation: 18878

Change your bannerView's frame:

let bannerView = GADBannerView(adSize: kGADAdSizeSmartBannerPortrait)
bannerView.frame = CGRect(x: 0.0,
                          y: UIApplication.sharedApplication().statusBarFrame.size.height,
                          width: bannerView.frame.width,
                          height: bannerView.frame.height)

Also, setting static positions is usually never a good idea. You can get the status bar's height with UIApplication.sharedApplication().statusBarFrame.size.height. This way, if the status bar height ever changes you don't have to worry about it.

Upvotes: 3

shuvo
shuvo

Reputation: 705

You can initiate the view as below:

let bannerView = GADBannerView(frame:CGRectMake(0, UIApplication.sharedApplication().statusBarFrame.size.height, CGSizeFromGADAdSize(kGADAdSizeSmartBannerPortrait).width, CGSizeFromGADAdSize(kGADAdSizeSmartBannerPortrait).height))

Upvotes: 2

Mat Grlt
Mat Grlt

Reputation: 131

You can change your bannerview's frame like this:

 bannerView.frame = CGRectMake(0, 20, bannerView.frame.width, bannerView.frame.height)

Upvotes: 0

Related Questions