Greg Gregorowski
Greg Gregorowski

Reputation: 35

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?

Upvotes: 0

Views: 259

Answers (1)

Vo Kim Nguyen
Vo Kim Nguyen

Reputation: 1633

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)

Upvotes: 1

Related Questions