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.
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.
您可以如下启动视图:
let bannerView = GADBannerView(frame:CGRectMake(0, UIApplication.sharedApplication().statusBarFrame.size.height, CGSizeFromGADAdSize(kGADAdSizeSmartBannerPortrait).width, CGSizeFromGADAdSize(kGADAdSizeSmartBannerPortrait).height))
您可以像这样更改bannerview的框架:
bannerView.frame = CGRectMake(0, 20, bannerView.frame.width, bannerView.frame.height)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.