I am integrating a Google AdMob banner ad into a UIView container that has the following constraints:
View Hierarchy
Main View (root view of UIViewController). Container View (inside Main View, used to hold adBannerView). adBannerView (added programmatically inside Container View).
UIViewController's Main View │ ├── Container View (UIView) │ ├── Ad Banner View (GADBannerView or other ad view)
Constraints Container View: Left: 0 (Aligns to the left of the main view) Right: 0 (Aligns to the right of the main view) Bottom: 0 (Sticks to the bottom of the main view) Height: 70 (Fixed height)
Ad Banner View: Same bounds as Container View (matches its frame)
- Container View is pinned to the bottom of the screen.
- Ad Banner View is programmatically added inside Container View and set to match its bounds.
- When the ad is loaded, it appears inside Container View without affecting other UI elements.
Here is my code for adding the banner ad:
func showAd(bannerViewContainer: UIView, VC: UIViewController) {
var bannerView: BannerView!
bannerView = BannerView(adSize: AdSizeFullBanner)
bannerView.adUnitID = bannerAdsId
bannerView.rootViewController = VC
bannerView.load(Request())
bannerView.frame = bannerViewContainer.bounds
bannerViewContainer.addSubview(bannerView)
}
However, when the ad appears on the screen, I notice that there is extra space on the left side of the banner. The banner is not aligned properly within the container view.
What I Have Tried:
- Checked the constraints - The container view has proper constraints (0 on left, right, and bottom).
- Set the banner frame explicitly - I tried manually setting
bannerView.frame = bannerViewContainer.bounds, but the issue persists. - Tried different ad sizes - Using
AdSizeBannerandAdSizeSmartBannerPortrait, but the issue remains.
Questions:
- Why is there extra left padding in the banner ad when it's inside a container with full width?

GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidthfrom official documentation?