Resize iP for MoPub?

I need my banner ads to be drawn / filled across the entire width of the screen below.

My code works for devices with a width equal to either MOPUB_BANNER_SIZE.width or MOPUB_LEADERBOARD_SIZE.width But on other devices (iPhone 5/6 / etc. And some iPads) my only option is to center the banner. here is the code:

if(!_mopubBanner){ NSString* bannerID; const CGSize* bannerSize; if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){ bannerID = @"MopubBannerId"; bannerSize = &MOPUB_BANNER_SIZE; } else{ bannerID = @"MopubLeaderboardId"; bannerSize = &MOPUB_LEADERBOARD_SIZE; } _mopubBanner = [[MPAdView alloc] initWithAdUnitId:bannerID size:*bannerSize]; _mopubBanner.delegate = self; CGRect BannerFrameRect; if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { BannerFrameRect = CGRectMake(([[UIScreen mainScreen] bounds].size.width - MOPUB_BANNER_SIZE.width) / 2, [[UIScreen mainScreen] bounds].size.height - MOPUB_BANNER_SIZE.height, MOPUB_BANNER_SIZE.width, MOPUB_BANNER_SIZE.height); } else { BannerFrameRect = CGRectMake(([[UIScreen mainScreen] bounds].size.width - MOPUB_LEADERBOARD_SIZE.width) / 2, [[UIScreen mainScreen] bounds].size.height - MOPUB_LEADERBOARD_SIZE.height, MOPUB_LEADERBOARD_SIZE.width, MOPUB_LEADERBOARD_SIZE.height); } _mopubBanner.frame = BannerFrameRect; } 

I tried setting custom sizes for the BannerFrameRect, but the banner ad just adjusts in the upper left corner of the new frame. It does not scale.

is there any way to resize the ad?

Thank you

+6
source share
2 answers

please see here MoPub code example:

https://github.com/mopub/mopub-ios-sdk/blob/master/MoPubSampleApp/Controllers/MPLeaderboardBannerAdDetailViewController.m

You can use automation in UIView, and in your case, you can simply add the following to your code:

  _mopubBanner.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin; 

hope this helps!

0
source

You have two viable solutions:

  • Use autoresist masks

     _mopubBanner.translatesAutoresizingMaskIntoConstraints = YES; _mopubBanner.autoresizingMask = UIViewAutoresizingFlexibleWidth; 

You will probably need to set the height manually, since you only need horizontal stretching.

  1. Significantly better IMO - use the self-timer. For this, I would recommend PureLayout , as it is really clear and useful.

     _mopubBanner.translatesAutoresizingMaskIntoConstraints = NO; [_mopubBanner autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeTop]; 
0
source

All Articles