Skip to content

Instantly share code, notes, and snippets.

@thomasmso
Created April 7, 2020 19:02
Show Gist options
  • Save thomasmso/1efb14eb30af7200bdcd9056496ff3a1 to your computer and use it in GitHub Desktop.
Save thomasmso/1efb14eb30af7200bdcd9056496ff3a1 to your computer and use it in GitHub Desktop.
- (void)createAdViewAdForAdFormat:(MAAdFormat *)adFormat
{
self.adView = [[MAAdView alloc] initWithAdUnitIdentifier: @"YOUR_AD_UNIT_ID"];
self.adView.delegate = self;
// Banners
if ( adFormat == MAAdFormat.BANNER || adFormat == MAAdFormat.LEADER )
{
// Banner height on iPhone and iPad is 50 and 90, respectively
CGFloat height = (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) ? 90 : 50;
// Stretch to the width of the screen for banners to be fully functional
CGFloat width = CGRectGetWidth(UIScreen.mainScreen.bounds);
self.adView.frame = CGRectMake(X, Y, width, height);
}
// MRECs
else // `MAAdFormat.MREC`
{
// MREC width and height on iPhone and iPad are 300 and 250, respectively
CGFloat width = 300;
CGFloat height = 250;
self.adView.frame = CGRectMake(X, Y, width, height);
}
// Set background or background color for banners to be fully functional
self.adView.backgroundColor = BANNER_BACKGROUND_COLOR;
[self.view addSubview: self.adView];
// Load the first ad
[self.adView loadAd];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment