简体   繁体   中英

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?

请为您的横幅添加位置

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)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM