如何在屏幕栏上方放置AdMob广告?

时间:2011-04-02 19:20:12

标签: iphone ipad admob tabbar ios4

我已经获得了AdMob的最新版iOS代码。它工作正常,但广告显示在我的标签栏下。如何将广告移到栏上方?这是我的相关代码:

#import "InformationViewController.h"


@implementation InformationViewController

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    // Create a view of the standard size at the bottom of the screen.

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        /* run something specific for the iPad */
        bannerView_ = [[GADBannerView alloc]
                       initWithFrame:CGRectMake(0.0,
                                                self.view.frame.size.height -
                                                GAD_SIZE_300x250.height,
                                                GAD_SIZE_300x250.width,
                                                GAD_SIZE_300x250.height)];
    } 
    else
    {
        /* run something specific for the iPhone */
        bannerView_ = [[GADBannerView alloc]
                       initWithFrame:CGRectMake(0.0,
                                                self.view.frame.size.height -
                                                GAD_SIZE_320x50.height,
                                                GAD_SIZE_320x50.width,
                                                GAD_SIZE_320x50.height)];
    }

    // Specify the ad's "unit identifier." This is your AdMob Publisher ID.
    bannerView_.adUnitID = MY_BANNER_UNIT_ID;

    // Let the runtime know which UIViewController to restore after taking
    // the user wherever the ad goes and add it to the view hierarchy.
    bannerView_.rootViewController = self;
    [self.view addSubview:bannerView_];

    // Initiate a generic request to load it with an ad.
    [bannerView_ loadRequest:[GADRequest request]];
}

我的头文件 -

#import "GADBannerView.h"

#import <UIKit/UIKit.h>


@interface InformationViewController : UIViewController {

    GADBannerView *bannerView_;

}

@end

1 个答案:

答案 0 :(得分:2)

你可以试试这个;

bannerView_ = [[GADBannerView alloc]
                       initWithFrame:CGRectMake(0.0,
                                                100.0 -
                                                GAD_SIZE_320x50.height,
                                                GAD_SIZE_320x50.width,
                                                GAD_SIZE_320x50.height)];

使用100以下的任何其他数字来移动横幅。希望这对你有用!