Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 15    Views: 881

Skywalker
Apple Fan
Profile
Posts: 117
Reg: Dec 25, 2013
上海
1,670
05/30/14 04:23 AM (10 years ago)

How to Change the position of the admob banner?

Here is the demo of adding admob banner, but it shows on the top of screen. If I want to shows the ad at the bottom of the screen, How can I do that? Which para should I change? Thanks for anyone who can help me! - (void)viewDidLoad { [super viewDidLoad]; // 在屏幕顶部创建标准尺寸的视图。 // 在GADAdSize.h中对可用的AdSize常量进行说明。 bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner]; // 指定广告单元ID。 bannerView_.adUnitID = MY_BANNER_UNIT_ID; // 告知运行时文件,在将用户转至广告的展示位置之后恢复哪个UIViewController // 并将其添加至视图层级结构。 bannerView_.rootViewController = self; [self.view addSubview:bannerView_]; // 启动一般性请求并在其中加载广告。 [bannerView_ loadRequest:[GADRequest request]]; }
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
05/30/14 11:53 AM (10 years ago)
I've not integrated admob but this should work. The chinese writing is giving me a bit of a headache though between this bannerView_.rootViewController = self; [self.view addSubview:bannerView_]; add this [bannerView_ setFrame:CGRectMake(0, CGRectGetHeight(self.view.frame)bannerView_.bounds.size.height, bannerView_.bounds.size.width, bannerView_.bounds.size.height)]; When you add a subview without a frame it defaults to the top left hand corner co-ordinates 0,0 This line of code makes a rectangle it starts at 0 width so dead on left, this part CGRectGetHeight(self.view.frame)bannerView_.bounds.size.height says hey get the height of the screen and then remove the height of the banner. This gives the starting y co-ordinate. Then we put the banner width and height in bannerView_.bounds.size.width, bannerView_.bounds.size.height Hope that makes a bit of sense.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
05/30/14 11:54 AM (10 years ago)
It will look like this bannerView_.rootViewController = self; [bannerView_ setFrame:CGRectMake(0, CGRectGetHeight(self.view.frame)bannerView_.bounds.size.height, bannerView_.bounds.size.width, bannerView_.bounds.size.height)]; [self.view addSubview:bannerView_];
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
05/31/14 07:47 AM (10 years ago)
Nice tip, Kittsy! I had not known about the default of 0,0. Makes sense now that you've said it out loud. :-)
 
KennedyE
Android Fan
Profile
Posts: 373
Reg: Dec 07, 2013
PH, Nigeria
3,730
like
05/31/14 11:21 AM (10 years ago)
What about menu button plugin android? I noticed the same problem when adding admob banner ads, even after when you set the banner ads to 'bottom' in the screen .xml file, the banner ad will still be on top. In which folder can this be corrected? And how can it be ccorrected?
 
Skywalker
Apple Fan
Profile
Posts: 117
Reg: Dec 25, 2013
上海
1,670
like
06/02/14 12:07 AM (10 years ago)
@Kittsy, Thanks for your solution, it works..^_^
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
06/02/14 12:55 AM (10 years ago)
Of course it does I'm Kittsy lol. @KennedyE I'm not completely up to date with android frames and xml, the summer it will eb getting smashed
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
07/25/14 08:08 AM (10 years ago)
@Kittsy & @Skywalker I've tried to add this code but I'm getting a parse error .. Expected ')' .. for some reason Here is my full code: bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner]; bannerView_.adUnitID = MY_BANNER_UNIT_ID; bannerView_.rootViewController = self; [bannerView_ setFrame:CGRectMake(0, CGRectGetHeight(self.view.frame)bannerView_.bounds.size.height, bannerView_.bounds.size.width, bannerView_.bounds.size.height)]; [self.view addSubview:bannerView_]; Thanks for any insight!
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
07/25/14 08:12 AM (10 years ago)
where is the yellow warning flag popping up
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
07/25/14 08:16 AM (10 years ago)
Actually it's a nasty red error :/ Right at the bannerView_: (self.view.frame)bannerView_
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
07/25/14 08:18 AM (10 years ago)
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
07/25/14 08:23 AM (10 years ago)
[bannerView_ setFrame:CGRectMake(0, CGRectGetHeight(self.view.frame)-bannerView_.bounds.size.height, bannerView_.bounds.size.width, bannerView_.bounds.size.height)]; there should be a minus CGRectGetHeight(self.view.frame)-bannerView_.bounds.size.height, it must have been stripped out somewhere
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
07/25/14 08:28 AM (10 years ago)
Ah perfect thanks! The error went away but no ads. Previously they did show at the top. Strange.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
07/25/14 08:31 AM (10 years ago)
is it a tab bar just to test change CGRectGetHeight(self.view.frame)-bannerView_.bounds.size.height, to CGRectGetHeight(self.view.frame)- 100,
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
07/25/14 08:45 AM (10 years ago)
Yeah its not a tab bar.. Strange :( I'll try to add it inside of the iad spot..
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
07/25/14 08:52 AM (10 years ago)
Based on another post, I replaced the iAD just in case someone else couldn't get it to work like me lol //create adView? if([[BT_strings getJsonPropertyValue:self.screenData.jsonVars nameOfProperty:@"includeAds" defaultValue:@"0"] isEqualToString:@"1"]){ bannerView_ = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height - GAD_SIZE_320x50.height -60, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)]; bannerView_.adUnitID = MY_BANNER_UNIT_ID; bannerView_.rootViewController = self; [self.view addSubview:bannerView_]; [bannerView_ loadRequest:[GADRequest request]]; }
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.