Resize TextView for 4" display? [duplicate] - ios

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;

Related

UIButton does not position itself correctly and not showing up in some devices - Objective C

I'm trying to align in center two buttons in a single-view application. I don't want to use auto-layout, i try to solve this case programmatically. So in my ViewController.m, in the ViewDidLoad() function, i've put the following code:
_firstButton.center = CGPointMake(self.view.center.x, self.view.frame.size.height/2.0-235);
_secondButton.center = CGPointMake(self.view.center.x, _secondButton.frame.size.height/2.0+(self.view.frame.size.height*0.9));
The secondButton is correctly positioned in any screen, on any device and on any simulator. The firstButton is positioned right only in iphone 5 and 5S simulators, but it does not even show up in my iPhone 5C device or the iPhone 6 & 6 Plus simulators.
What am i doing wrong, what do i miss here?
Thanks in advance
ps: objective-c noob here, sorry if that's a too dumb question
In viewDidLoad the frame is not set yet. I recommend you to do it in viewWillAppear
Be sure it is NOT a dumb question.
As a little help, I can tell you I find easier to handles layout with main xib with auto layout.
Otherwise, for multiple screens sizes, you could manage sizes or positions as relatives to actual screen size : UIScreen.mainScreen().bounds, for instance, in case of sizes :
let screenSize: CGRect = UIScreen.mainScreen().bounds
let sreenHeight = screenSize.height
let screenWidth = screenSize.width
let cardwidth = screenSize.width * 0.47
let cardheight = screenSize.height * 0.47
let ViewBackGround = UIView(frame:CGRectMake(0, 0, cardwidth * 0.8, cardwidth))

Trying to detect iPhone 6 Plus in landscape orientation

I have a today widget for my app and I have been setting the layout of objects in code (Not using auto-layout) however, I need to detect when a user is using an iPhone 6 Plus. The reason for this is because in notification centre on the 6 Plus, there is a border around the edge which cuts off the labels in my widget (in landscape).
The problem is that I have been having issues trying to figure out what height value the screen is in landscape.
This is the code I have right now:
var height = UIScreen.mainScreen().bounds.size.height
if UIDevice.currentDevice().orientation.isLandscape && height == 414 {
totalBudgetDisplay.frame.origin.x = UIScreen.mainScreen().bounds.width - 250
currentBudgetDisplay.frame.origin.x = UIScreen.mainScreen().bounds.width - 250
budgetNameDisplay.frame.origin.x = 80
warningLabel.center = view.center
button.frame = CGRectMake(0, 0, view.bounds.width, view.bounds.height)
}
Is this the correct value for the screen height in landscape? If so, why are the labels still not moving?
Your code is good but UIDevice.currentDevice().orientation.isLandscape just does not get you correct value.
Seems like there is no bullet-proof solution to detect device orientation for Extensions.
Look at this answer for possible workaround - https://stackoverflow.com/a/26023538/2797141

iOS admob stick to the bottom of screen [duplicate]

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

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

Under iOS 7, how do I make my UITextView's height dependent on the type of device running the app (4 inch screen vs 3.5)

I have a UITextView that should consume the height of the screen, minus the height of the nav bar and keyboard (as when the view loads the keyboard appears). Obviously on a 4 inch device this means the text view should be slightly taller. Is it possible in Interface Builder to make the height device dependent?
If not, can I do it in code? Is it possible to do without some Auto Layout constraints?
It would be very easy to do it by using Auto Layout constraints. Is there any special reason for not using it?
You need to do this check in your code, You can use below Macor to check the device:
#define IS_IPHONE5 ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE
then:
if (IS_IPHONE5 )
{
//textView.frame = ..
}
else
{
//textView.frame = ..
}
And yes you can do it using a couple of Auto Layout constraints which is the best practice to do that, check this SO question:
iPhone 4 & 5 Autoresize Vertical Space
you can use struts and springs. but auto layout is the new hotness.
iOS AutoLayout vs Springs & Struts
Going off null's answer:
Im assuming you are placing this UITextView inside a UIViewController?
You can set the frame for the UITextView at runtime.
In viewDidLoad:
-(void)viewDidLoad {
UITextView *textView = [[UITextView alloc] init];
//216 is the height of the keyboard, 20 is the height of the status bar
if (isiPhone5) {
CGRect frame = CGRectMake(0, self.navigationBar.frame.size.height + 20, self.frame.size.width, 568-216);
[textView setFrame:frame];
}
else {
CGRect frame = CGRectMake(0, self.navigationBar.frame.size.height + 20, self.frame.size.width, 480-216);
[textView setFrame:frame];
}
}

Resources