I’m integrating a Google AdMob banner advert right into a UIView container that has the next constraints:
View Hierarchy
Major View (root view of UIViewController).
Container View (inside Major View, used to carry adBannerView).
adBannerView (added programmatically inside Container View).
UIViewController’s Major View
│
├── Container View (UIView)
│ ├── Advert Banner View (GADBannerView or different advert view)
Constraints
Container View:
Left: 0 (Aligns to the left of the primary view)
Proper: 0 (Aligns to the suitable of the primary view)
Backside: 0 (Sticks to the underside of the primary view)
Top: 70 (Fastened peak)
Advert Banner View:
Similar bounds as Container View (matches its body)
- Container View is pinned to the underside of the display screen.
- Advert Banner View is programmatically added inside Container View and set to match its bounds.
- When the advert is loaded, it seems inside Container View with out affecting different UI components.
Right here is my code for including the banner advert:
func showAd(bannerViewContainer: UIView, VC: UIViewController) {
var bannerView: BannerView!
bannerView = BannerView(adSize: AdSizeFullBanner)
bannerView.adUnitID = bannerAdsId
bannerView.rootViewController = VC
bannerView.load(Request())
bannerView.body = bannerViewContainer.bounds
bannerViewContainer.addSubview(bannerView)
}
Nevertheless, when the advert seems on the display screen, I discover that there’s additional area on the left facet of the banner. The banner will not be aligned correctly inside the container view.
What I Have Tried:
- Checked the constraints – The container view has correct constraints (0 on left, proper, and backside).
- Set the banner body explicitly – I attempted manually setting
bannerView.body = bannerViewContainer.bounds
, however the concern persists. - Tried totally different advert sizes – Utilizing
AdSizeBanner
andAdSizeSmartBannerPortrait
, however the concern stays.
Questions:
- Why is there additional left padding within the banner advert when it is inside a container with full width?