开发者

iAd Banner background image

i was wondering how can i change t开发者_Go百科he iAd black background image ?

iAd Banner background image


You can't in a standard iPhone application run in the Simulator. This is simply a test advertisement that Apple served to your application.

If you wish to try out other iAd designs that you are building, you need to grab the iAd JS framework from the iOS Dev Center. This will install an iAd Tester application in the Simulator which allows you to test iAd builds.


I am dividing this task into 3 simple steps.

Step 1:

  1. import iAd Framework to the Application.

  2. Provide #import <iAd/iAd.h> in the particular controller where you want to show your Ad.

  3. Provide its delegate UIViewController <ADBannerViewDelegate>

  4. Provide one view to that particular ViewController. Assume I have taken

@property (weak, nonatomic) IBOutlet UIView *contentView;

Step 2:

//Allocate it in ViewDidLoad method


- (void)viewDidLoad

{

_bannerView = [[ADBannerView alloc] init];

_bannerView.delegate = self;

[super viewDidLoad];

[self.view addSubview:_bannerView];

}

Step 3:

Provide its delegate methods which I have mentioned below.

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
[self layoutAnimated:duration > 0.0];
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
[self layoutAnimated:YES];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
[self layoutAnimated:YES];
}

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{

return YES;
}

- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{

}
- (void)layoutAnimated:(BOOL)animated
{
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}

CGRect contentFrame = self.view.bounds;
CGRect bannerFrame = _bannerView.frame;
if (_bannerView.bannerLoaded) {
contentFrame.size.height -= _bannerView.frame.size.height;
bannerFrame.origin.y = contentFrame.size.height;
} else {
bannerFrame.origin.y = contentFrame.size.height;
}

[UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{
self.contentView.frame = contentFrame;
[self.contentView layoutIfNeeded];
_bannerView.frame = bannerFrame;
}];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜