[英]How to put Admob banner for iOS on bottom centre?
I am using this code to put the banner ads on bottom left.我正在使用此代码将横幅广告放在左下角。
CGPoint origin = CGPointMake(0.0,
self.view.frame.size.height -
CGSizeFromGADAdSize(kGADAdSizeBanner).height);
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
origin:origin];
How to position the banner at bottom center?如何将横幅放置在底部中心?
You just have to add it as a subview after initialization:您只需在初始化后将其添加为子视图:
CGPoint origin = CGPointMake(0.0, self.view.frame.size.height - CGSizeFromGADAdSize(kGADAdSizeBanner).height);
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
origin:origin];
bannerView_.center = CGPointMake(self.view.center.x, self.view.frame.size.height-CGSizeFromGADAdSize(kGADAdSizeBanner).height/2)
[self.view addSubview: bannerView_];
After some trial and error, this code helped me center banner ad to the bottom.经过反复试验,此代码帮助我将横幅广告置于底部。 The Google admob documentation helped as well.
Google admob 文档也有帮助。
func addBannerViewToView(_ bannerView: GADBannerView) {
bannerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bannerView)
view.addConstraints(
[NSLayoutConstraint(item: bannerView,
attribute: .bottom,
relatedBy: .equal,
toItem: view.safeAreaLayoutGuide,
attribute: .bottom,
multiplier: 1,
constant: 0),
NSLayoutConstraint(item: bannerView,
attribute: .centerX,
relatedBy: .equal,
toItem: view.safeAreaLayoutGuide,
attribute: .centerX,
multiplier: 1,
constant: 0)]
)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.