简体   繁体   中英

How do I make my iAd banner appear at bottom of screen?

I have the following code that allows me to position it on the top. I am wanting it to appear at the bottom.

 adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
 adView.frame = CGRectOffset(adView.frame, 0, -50);
 adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
 adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
 [self.view addSubview:adView];

Any assistance will be appreciated.

Update—@larsacus pointed out this is for 4.2+:

adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
CGRect adFrame = adView.frame;
adFrame.origin.y = self.view.frame.size.height-adView.frame.size.height;
adView.frame = adFrame;
[self.view addSubview:adView];

显示在模拟器中工作

My first answer on SO :)

Why not use the 'center' property of the adView? If the dimensions of your main view are viewWidth and viewHeight:

//at the bottom of view,centered
adView.center=CGPointMake(viewWidth/2, viewHeight-adView.frame.size.height);

//at the top, right corner ;)
adView.center=CGPointMake(viewWidth-adView.frame.size.width/2, adView.frame.size.height);

Cheers

这是帮助我将视图移到底部的原因:

adFrame.origin.y = self.view.frame.size.height;

adView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;

Using Storyboards, then, ignore that the standard iAd Banner View does not reach the edges of the screen. Set the iAd banner to be centred, then move it to as close to the bottom as you want. No other width settings (no leading or trailing settings)

Mine looked ok with 8 pixels from the bottom of the superview, but I went with - pixels between the iAd banner and the UIController View.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM