Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
161 views
in Technique[技术] by (71.8m points)

ios - GADBannerView ad not full width while displaying inside UIStackView

I'm displaying GADBannerView in my app.

lazy var bannerView: GADBannerView = {
    let b = GADBannerView(adSize: kGADAdSizeSmartBannerPortrait)
    b.adUnitID = "... id ..."
    b.rootViewController = self
    b.load(GADRequest())
    return b
}()

It works ok if I display it as a subview of 'self.view'.

self.view.addSubview(contentView)
self.view.addSubview(bannerView)
// autolayout for contentView and bannerView ...

good display ...

enter image description here

But as some requirement, I want to display it inside a vertical UIStackView.

let stack = UIStackView(arrangedSubviews: [contentView, bannerView])
stack.axis = .vertical
stack.distribution = .equalSpacing
stack.alignment = .fill

// autolayout for stack view ...

The problem appears that the ad showing not full width with 2 black ends (left and right) as the image below

bad display ...

enter image description here

I tried Debug View Hierarchy of the GADBannerView and it's all subviews. All seem ok, full size, equal to outer view, 375 as I tested with iPhone 12 mini, as image below

enter image description here enter image description here

I cannot figure out the problem. If you know this, please help me. Thank you!

question from:https://stackoverflow.com/questions/65878652/gadbannerview-ad-not-full-width-while-displaying-inside-uistackview

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...