Center Banner Ads

616 views
Skip to first unread message

Hamed Hashemi

unread,
Oct 28, 2015, 7:41:42 PM10/28/15
to Google Mobile Ads SDK Developers
When using kGADAdSizeSmartBannerPortrait banner sizes, is there a way to make sure the creative is centered? Since most ads are 320 pixels in width, they left align on wider devices such as iPhone 6 and 6 Plus. I have this problem with different creatives as well as custom creatives created in DFP. I have also taken a look at the webview that serves the ad, and the width is the device pixels, which makes it really hard to fix this in code.

Vu Chau (MobileAds SDK Team)

unread,
Oct 29, 2015, 12:21:31 PM10/29/15
to Google Mobile Ads SDK Developers
Hi Hamed,

If the width of your kGADAdSizeSmartBannerPortrait doesn't consume that of the device, the SDK should center it as noted in our docs.  Would you mind sharing with us some code snippets and the respective ad unit IDs?

Thanks,

Vu Chau
Mobile Ads SDK Team

Ron Franczyk

unread,
Jan 18, 2016, 6:05:14 PM1/18/16
to Google Mobile Ads SDK Developers
I have the same issue, it appears with custom creatives for DFP the ads left align and do not center. 26591627 / AppAd320x50Mobile is the account and add unit id. Non DFP creative ads seem to display centered, this one doesn't

Ron

Vu Chau (MobileAds SDK Team)

unread,
Jan 19, 2016, 9:58:49 AM1/19/16
to Google Mobile Ads SDK Developers
Hi Ron,

I was able to see the creative from that account and ad unit ID centered in the activity (see screenshot).  Could you take a look and confirm? Are you able to reproduce the issue in our sample app?

Vu Chau
Mobile Ads SDK Team

Screen+Shot+2016-01-19+at+9.46.29+AM.png

Ron Franczyk

unread,
Jan 19, 2016, 2:30:10 PM1/19/16
to google-adm...@googlegroups.com

So i'm adding the banner to the view as a subView - here is the code I'm using - when I do this, it left aligns it, is there something I'm doing wrong you can see?



- (void)viewDidLoad {

  [super viewDidLoad];


    _dfpADBannerAd = [[DFPBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];

    _dfpADBannerAd.center = CGPointMake(_dfpADBannerAd.bounds.size.width  / 2,

                                        _dfpADBannerAd.bounds.size.height / 2);

    

    _dfpADBannerAd.delegate = self;

    _dfpADBannerAd.adUnitID = @"/26591627/AppAd320x50Mobile";

    _dfpADBannerAd.rootViewController = self;

    [_dfpADBannerAd loadRequest:[DFPRequest request]];

    

    [[self view] addSubview:_dfpADBannerAd];

    

}


--

---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/2EXRmdEcYPw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--



Ron Franczyk

Red Foundry, Inc.

1608 S. Ashland Ave.

Chicago, IL 60608

Direct Line:  630.791.0301

Office:  888.406.1099 

Email:  r...@redfoundry.com

Web:  www.redfoundry.com

Skype:  rfranczyk

Twitter: @rfranczyk

Vu Chau (MobileAds SDK Team)

unread,
Jan 19, 2016, 5:04:10 PM1/19/16
to Google Mobile Ads SDK Developers
Hi Ron,

Looks like your Storyboard constraints aren't set here.  You should be able to center the banner using the following:

self.bannerView = [[DFPBannerView alloc] initWithAdSize:kGADAdSizeBanner];
bannerView.rootViewController = self;
[bannerView setAdUnitID:@"/26591627/AppAd320x50Mobile"];

bannerView.delegate = self;
[self.view addSubview:bannerView];

bannerView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                             attribute:NSLayoutAttributeBottom
                                                             relatedBy:NSLayoutRelationEqual
                                                                toItem:self.view
                                                             attribute:NSLayoutAttributeBottom
                                                            multiplier:1
                                                              constant:0]];

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:bannerView
                                                             attribute:NSLayoutAttributeCenterX
                                                             relatedBy:NSLayoutRelationEqual
                                                                toItem:self.view
                                                             attribute:NSLayoutAttributeCenterX
                                                            multiplier:1
                                                              constant:0]];

DFPRequest *request = [DFPRequest request];
[self.bannerView loadRequest:request];
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ron Franczyk

unread,
Jan 19, 2016, 5:29:46 PM1/19/16
to google-adm...@googlegroups.com
Thanks! however it appears if I set the Size to SmartBanner it still left aligns it - is that expected? Will smart banner custom creatives always be left aligned?



To unsubscribe from this group and all its topics, send an email to google-admob-ads...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--



Ron Franczyk

Red Foundry, Inc.

1608 S. Ashland Ave.

Chicago, IL 60608

Direct Line:  630.791.0301

Office:  888.406.1099 

Email:  r...@redfoundry.com

Web:  www.redfoundry.com

Skype:  rfranczyk

Twitter: @rfranczyk

--

---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/2EXRmdEcYPw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Vu Chau (MobileAds SDK Team)

unread,
Jan 20, 2016, 10:25:29 AM1/20/16
to Google Mobile Ads SDK Developers
Hi Ron,

Testing it in our sample app using the default settings (i.e. with the Storyboard constraints in place), I was able to see the smart banner from your ad unit ID centered.  I'd suggest keeping the Storyboard constraints, or if you are working with the dynamic constraints provided earlier, try the following more comprehensive set:

_bannerView = [[DFPBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
    
    self.bannerView.adSize = kGADAdSizeSmartBannerPortrait;
    self.bannerView.adUnitID = @"/26591627/AppAd320x50Mobile";
    self.bannerView.rootViewController = self;
    [self.view addSubview:_bannerView];

    _bannerView.translatesAutoresizingMaskIntoConstraints = NO;

    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_bannerView
                                                          attribute:NSLayoutAttributeBottom
                                                          relatedBy:NSLayoutRelationEqual
                                                          toItem:self.view

                                                          attribute:NSLayoutAttributeBottom
                                                          multiplier:1
                                                          constant:0
]];
   
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_bannerView
                                                          attribute:NSLayoutAttributeCenterX
                                                          relatedBy:NSLayoutRelationEqual
                                                          toItem:self.view

                                                          attribute:NSLayoutAttributeCenterX
                                                          multiplier:1
                                                          constant:0
]];

    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_bannerView
                                                          attribute:NSLayoutAttributeWidth
                                                          relatedBy:NSLayoutRelationEqual
                                                          toItem:nil
                                                          attribute:NSLayoutAttributeNotAnAttribute
                                                          multiplier:1
                                                          constant:320]];

    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_bannerView
                                                          attribute:NSLayoutAttributeHeight
                                                          relatedBy:NSLayoutRelationEqual
                                                          toItem:nil
                                                          attribute:NSLayoutAttributeNotAnAttribute
                                                          multiplier:1
                                                          constant:50]];
    [self.bannerView loadRequest:[DFPRequest request]];
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--



Ron Franczyk

Red Foundry, Inc.

1608 S. Ashland Ave.

Chicago, IL 60608

Direct Line:  630.791.0301

Office:  888.406.1099 

Email:  r...@redfoundry.com

Web:  www.redfoundry.com

Skype:  rfranczyk

Twitter: @rfranczyk

--

---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/2EXRmdEcYPw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages