swift admobバナー広告位置調整(なんかのUIの上か下に置きたいとき)
adMobバナー広告の位置調整
2021/03/15追記:アダプティブバナーの場合は正常に動作しない可能性があります。
//これ公式サイトにのてっるコードです
func addBannerViewToView(_ bannerView: GADBannerView) {
bannerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bannerView)
view.addConstraints(
[NSLayoutConstraint(item: bannerView,
attribute: .bottom,
relatedBy: .equal,
toItem: 何かの上に配置したいときはここにそのUI,
attribute: .top,
multiplier: 1,
constant: 0),
NSLayoutConstraint(item: bannerView,
attribute: .centerX,
relatedBy: .equal,
toItem: 何かの下に配置したいときはここにそのUI,
attribute: .centerX,
multiplier: 1,
constant: 0)
])
}