如何在顶级中心定位iOS的Admob Banner?

时间:2015-07-26 06:28:00

标签: ios objective-c admob

我正在使用此代码将Admob横幅定位在左上角。如何将位置更改为顶部中心?

bannerView_ = [[[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner]
    autorelease];
    bannerView_.adUnitID = @"my-id";
    bannerView_.rootViewController = self;
    [self.view addSubview:bannerView_];
    [bannerView_ loadRequest:[GADRequest request]];

2 个答案:

答案 0 :(得分:0)

bannerView_ = [[GADBannerView alloc]initWithFrame:CGRectMake(0, 0, 25, 50)];
    // Need to set this to no since we're creating this custom view.
    abmob.translatesAutoresizingMaskIntoConstraints = NO;

    // Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID
    // before compiling.
    bannerView_.adUnitID = AdMob_ID;
    bannerView_.delegate = self;
    [bannerView_ setRootViewController:self];
    [self.view addSubview:bannerView_];
    [bannerView_ loadRequest:[self createRequest]];

可能有帮助。

答案 1 :(得分:0)

初始化这样的横幅广告:

bannerView_ = [[GADBannerView alloc] init];

给它这样的帧大小:

bannerView_.frame =  frameSize;

对于帧大小,你可以在你喜欢的任何地方在你的笔尖中创建一个UIView并给它的frameSize,即它的boundsbannerView_.frame,或者你也可以直接给横幅广告提供帧大小:

bannerView_ = [[GADBannerView alloc]initWithFrame:CGRectMake(0, 0, width, height];