答案 0 :(得分:4)
您可以将GADBannerView
添加到您设置UIView
的其他backgroundColor
。这需要使用AdMob的default sizes来确保图片横幅正确合适。这样下降的基础是,基于文字的广告也会限制在此尺寸,而不是填充整个广告区域。
例如:
#import "ViewController.h"
@import GoogleMobileAds;
#define ADUNIT_ID @"yourAdUnitID"
@interface ViewController () <GADBannerViewDelegate> {
GADBannerView *admobBanner;
UIView *backgroundView;
}
@end
@implementation ViewController
-(void)viewDidLoad {
[super viewDidLoad];
// Create our AdMob banner
admobBanner = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
admobBanner.adUnitID = ADUNIT_ID;
admobBanner.rootViewController = self;
admobBanner.delegate = self;
[admobBanner loadRequest:[GADRequest request]];
// Create a view to put our AdMob banner in
backgroundView = [[UIView alloc]initWithFrame:CGRectMake(0,
self.view.frame.size.height - admobBanner.frame.size.height,
self.view.frame.size.width,
admobBanner.frame.size.height)];
// Hide view until we have an ad
backgroundView.alpha = 0.0;
// Set to color you require
backgroundView.backgroundColor = [UIColor redColor];
// Add our views
[self.view addSubview:backgroundView];
[backgroundView addSubview:admobBanner];
// Center our AdMob banner in our view
admobBanner.center = [backgroundView convertPoint:backgroundView.center fromView:backgroundView.superview];
}
-(void)adViewDidReceiveAd:(GADBannerView *)adView {
NSLog(@"adViewDidReceiveAd");
[UIView animateWithDuration:0.5 animations:^{
backgroundView.alpha = 1.0;
}];
}
-(void)adView:(GADBannerView *)adView didFailToReceiveAdWithError:(GADRequestError *)error {
NSLog(@"adView:didFailToReceiveAdWithError: %@", [error localizedDescription]);
[UIView animateWithDuration:0.5 animations:^{
backgroundView.alpha = 0.0;
}];
}
iPhone / iPad
答案 1 :(得分:3)
这实际上是通过AdMob的信息中心实现的。
可能需要几分钟才能在您的应用程序中显示更改。
答案 2 :(得分:-1)
我认为你应该填写UIView相同Admob大小的矩形。
bannerView = GADBannerView(frame: rectBanner)
bannerView.adUnitID = "xxxxxxxxxxxxxxxxxx"
bannerView.rootViewController = self
帧大小(rectBanner)应与Admob Size匹配。