user2872856
user2872856

Reputation: 2051

How to Position Admob Banner for iOS on Top Centre?

I am using this code to position the Admob banner on top left. How to change the position to top centre?

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

Upvotes: 0

Views: 1253

Answers (2)

Munahil
Munahil

Reputation: 2419

Initialize a banner ad like this :

bannerView_ = [[GADBannerView alloc] init];

Give it frame size like this:

bannerView_.frame =  frameSize;

For frame size, you can make a UIView in your nib at whatever place you like and give its frameSize, i.e its bounds to bannerView_.frame or you can also directly give frame size to banner ad directly:

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

Upvotes: 1

nandu kathmandi
nandu kathmandi

Reputation: 33

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]];

May be it helps.

Upvotes: 1

Related Questions