iOS admob stick to the bottom of screen [duplicate] - ios

This question already has answers here:
Set Admob banner to appear at bottom of screen
(2 answers)
Closed 8 years ago.
I'm developing a new app and I'm using initWithAdSize:kGADAdSizeSmartBannerPortraitbut as default it stickes add to top. How can I make it to stcick ads to bottom of screen? Thanks!
bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
bannerView_.adUnitID = #"xxxxxxxxxxxxxxxxxxxxx";
bannerView_.rootViewController = self;
[self.view addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];

I set the frame below such that it always show ad at bottom on all iOS devices:
bannerView_.frame = CGRectMake(screenWidth/2.0 - bannerView_.frame.size.width/2.0
, screenHeight - bannerView_.frame.size.height
,bannerView_.frame.size.width
,bannerView_.frame.size.height);

Try adding this:
bannerView_.center = CGPoint(x: bannerView_.center.x, y: view.bounds.size.height - bannerView_.frame.size.height / 2)
This correctly positions the ad on the bottom for me. It also works for all iphones/ipads on simulator. However, this code is in swift. I think the code is similar, if not the same, in objective C.
Hope this helps!

Did you try to play with autoSizing ? Try setting to bottom, left, right and flexible width. I did this to make some of my views alway stick to bottom and it adjusts itself for 4" retina too if initially designed for 3.5" (retina).

In Objective-C, the following initialization sets the banner to the bottom of the screen:
bannerView = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, self.view.frame.size.height-GAD_SIZE_320x50.height, self.view.frame.size.width, GAD_SIZE_320x50.height)];

Related

How to create a portrait iAd banner view for iPhone/iPad

In Apple iAd programming guide, in the apple developer library with a date of 9/17/14, I'm looking to make that when user clicks on iAd banner and game is in Portrait mode, that the banner shows in portrait mode and not landscape like i'm currently getting. The following is the code I found in the 9/17/14 version of iAd programming guidelines.
ADBannerView *adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:adView];
Problem is Xcode 6.1 tells me ADBannerContentSizeIdentifierPortrait has been deprecated after iOS 6.0. Don't know why a deprecated code was inside a 9/17/14 made guideline. So what is the non-depracated code to make the iPad/iPhone load iAd in Portrait or UpsideDown mode?
First you could try self.canDisplayBannerAds = YES;
Second, you could make an ADBannerView and set the size due to the orientation.
ADBannerView *banner = [[ADBannerView alloc] init];
if([UIScreen mainScreen].bounds.size.width < [UIScreen mainScreen].bounds.size.height){
banner.frame = CGRectMake(0, 0, 120, 640);
[self.view addSubview:banner];
}

Facebook Login Button Alignment iOS

I need some help on aligning the facebook login button programatically.
Here is the code that facebook sdk gives you and places it in the center at the top of the storyboard.
I want to align it at a specific spot towards the bottom of my storyboard. This is where the SDK places it: http://i.imgur.com/HN08YqN.png ......Here is where i want to place it: http://i.imgur.com/JWECyr0.png
Thanks folks.
//Facebook Login Button
FBLoginView *loginView = [[FBLoginView alloc] init];
// Align the button in the center horizontally
loginView.frame = CGRectOffset(loginView.frame, (self.view.center.x - (loginView.frame.size.width / 2)), 5);
[self.view addSubview:loginView];
Try setting the center property instead of the frame. That is how I do it.
loginView.center = CGPointMake(selfWidth /2, selfHeight - 40);

How to adjust UITableview margins from left and right programmatically?

i have a tableview(no table view cell). My Application is running fine in iOS 6 but when i am running it in iOS7 Tableview margin is conflicting.When i am setting up frame via Code its margin is only adjusting from left and bottom. i am using following code
if([[[UIDevice currentDevice]systemVersion]floatValue]>=7){
CGRect newSize = CGRectMake(0,0,730,925);
newSize.origin.y = 0;
newSize.size.width = 728.0;
newSize.size.height = 925.0;
self.myTable.frame = newSize;
}
Please suggest me something how can i resolve it
?
Here are images for ios 6 & ios 7 (Its a group table view ) i havent changed any margin for ios 7 its same as in ios6 ,and if i am doing any changes in ios 7 regarding margin its affecting in ios 6 layout too..
Add autoresize property
//ensure autosizing enabled
self.view.autoresizesSubviews = YES;
myTable = [[myTable alloc]initWithFrame:self.view.bounds];
[myTable setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[self.view addSubview:myTable];

Resize TextView for 4" display? [duplicate]

This question already has answers here:
How to develop or migrate apps for iPhone 5 screen resolution?
(30 answers)
Closed 8 years ago.
How do I resize a text view so that it expands when displayed in the new 4" screens that it isn't shorter? I'm using AutoLayout. Also, I calculated that since the iOS keyboard takes up 216 points on both devices, and since the Navigation bar takes up 44 points on both devices, that the remaining view would be 200 points on a 320x460 screen. But how do I set this relative to the iPhone 5 screen? Any help would be appreciated. I've provided a screenshot to illustrate what I mean to better understand my issue.
Normal Screen (Works great!):
iPhone 5 Screen (Not so great!):
Try do like this:
self.view.autoresizesSubviews = YES;
self.textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Just ended up disabling autolayout for that specific view controller, and set my own CGRect.
CGRect largeScreen = CGRectMake(0, 1, 640, 290);
CGRect screenBounds = [[UIScreen mainScreen]bounds];
if (screenBounds.size.height==568)
{
[self.htmlText setTranslatesAutoresizingMaskIntoConstraints:YES];
htmlText.frame = largeScreen;
}
It is quite simple calculate height of textfield like this
CGFloat TextFieldHeight = self.view.frame.size.height - keyboardHeight- statusbarheight - navigationBarHeight;
Then assign this height to your textfield.
CGRect TextFieldNewFrame = textField.frame;
TextFieldNewFrame.size,height = TextFieldHeight;
textField.frame = TextFieldNewFrame;

Show UIButton over an Admob Banner?

I'm trying to display a UIButton over an AdmobBanner like the example below (the black X obviously). I looked for this option in the Admob SDK but couldn't find anything.
I've tried selecting the button->Editor->Arrange->Send to Front with no results.
Help is much appreciated.
This is the code I use to show my banner:
CGPoint origin = CGPointMake(0.0,0.0);
// Use predefined GADAdSize constants to define the GADBannerView.
self.adBanner = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner
origin:origin];
// Note: Edit SampleConstants.h to provide a definition for kSampleAdUnitID
// before compiling.
self.adBanner.adUnitID = #"a150xxxxxxxxxxx";
self.adBanner.delegate = self;
[self.adBanner setRootViewController:self];
[self.view addSubview:self.adBanner];
self.adBanner.center =
CGPointMake(self.view.center.x, self.adBanner.center.y);
[self.adBanner loadRequest:[self createRequest]];
Im assuming you're using interface builder here, and that both the AdMob view and your button are subviews of the same parent view. If that is the case, just make sure the button comes before the AdMob view in the list of subviews in the Objects pane on the left.
Another option is to make the following call in viewDidLoad:
[self.view bringSubviewToFront:button]
Make sure you do this after inserting the AdMob view, if you're doing it programmatically

Resources