Greg Gregorowski Greg Gregorowski -4 years ago 118
Swift Question

Admob banner in the middle of toolbar

Is it possible to put admit banner in the middle of

navigationController.toolbar
? Way I did it (inside
viewDidLoad
):

let banner = GADBannerView(adSize: kGADAdSizeBanner)
banner.adUnitID="ca-app-pub-123"
banner.rootViewController=self
banner.load(GADRequest())
self.navigationController?.isToolbarHidden=false
self.navigationController?.toolbar.addSubview(banner)
self.navigationController?.toolbar.sizeToFit()


However banner is aligned to the left side of a toolbar. Is there a simple way to align banner to the middle?

Answer Source

Please add position for your banner

banner.frame.origin = CGPoint(x: self.navigationController?.toolbar.frame.width / 2 - banner.frame.width / 2, y: self.navigationController?.toolbar.frame.height / 2 - banner.frame.height / 2)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download