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]];
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.
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, ie 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];
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.