Contents clipped using autolayout in 3.5 inch screen - ios

i am using autolayout in my project. I added the contraints from the bottom to the top. Everything works fins in 4 inch screen . But screen is clipped when the project is run on 3.5 simulator.

Looking at the screenshots, it looks like there is no space to fit all your elements.
One way to go about it is, dock the elements at the top of the screen using the Top Space To Superview constraint, and dock the elements at the bottom using the Bottom Space To Superview constraint.
When you do this, if there's not enough space available, you'll probably see some of your subviews overlapping around the middle.
You can consider solving this by using a UIScrollView as a top level subview and add all your subviews to the scrollView. The content height of the scrollView will be calculated based on your constraints.
You can also manually set the contentView height after viewDidLayoutSubviews is called.

Personally I find that sometimes I can't seem to get Autolayout to work exactly as I want. So its worth putting a check in your viewDidLoad to manually move objects around a bit if the screen size is a 3.5 inch screen like so:
In my example I will be using a Button:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
CGSize result = [[UIScreen mainScreen] bounds].size;
if (result.height == 480) {
// 3.5 inch display
button.frame = CGRectOffset(button.frame, 0, 89.0f);
}
if (result.height >= 568) {
// 4 inch display
// .....
}
}

Related

Bottom UIToolbar off screen on iPhone 4 and 4S

My problem is very similar to UIToolbar not displaying on iPhone 4 and iPhone 4s
I am using Xcode 7 and am trying to get a 'legacy' UINavigationController based iPhone app up and running on various iPhone screen sizes. By legacy , I mean it does not use Storyboards etc. The views are loaded from an .xib.
The app is a classic UINavigationController app with UITableViewControllers but with a UIToolBar at the bottom underneath the table view. The TableView and ToolBar are subviews of the view of the ViewController.
Works great on iPhone5/5s/6/6s.
But on the iPhone 4/4s the toolbar is off the screen. Oddly if I rotate the screen to landscape, the toolbar appears. Rotate back, it vanishes. I know this seems like prehistoric iOS code, but I am completely at a loss here and have wasted hours fiddling in Xcode and IB. I know I am missing something obvious.
It seems like the height of your table view is set to be a fixed height where the toolbar is visible beneath the table view on iPhone 5 and up. To get the toolbar to display on iPhone 4/4s requires reducing the height of the table view's frame using something like the following code.
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if (onIphone4 && portraitOrientation) {
CGFloat height = 480 - self.toolbar.frame.size.height;
self.tableView.frame = CGRectMake(0, 0, 320, height); // for iPhone 4/4s
} else if (onIphone5 && portraitOrientation) {
CGFloat height = 568 - self.toolbar.frame.size.height;
self.tableView.frame = CGRectMake(0, 0, 320, height); // for iPhone 5 and up
}
}
You will probably need to change the y position in the frame origin to account for the status bar and navigation bar if they are also present. In that case, the overall frame height will need to be adjusted for those changes. This is the frame-based way of adjusting view sizes.
The alternative and preferred method is to add auto layout constraints in the XIB for the toolbar and the table view in Interface Builder so that they will maintain the proper size and position relative to the screen dimensions.
I found the issue.. it was the "Full Screen at Launch" checkbox in IB, for the main "UIWindow"... and I quote from Apple documentation....
"If you choose to create a window in Interface Builder, be sure to select the Full Screen at Launch option in the Attributes inspector so that the window is sized appropriately for the current device."
Now please excuse me while I slam head against wall..way to waste a Sunday!

Positioning views dependent on device height in iOS

I'm switching to autolayout and I'd like to position views relatively to height of device. How should I setup constraints to satisfy such condition.
I have nice layout for iPhone 5 but for iPhone 6Plus I'd like to move "red" to position of "gray":
All my current constrains:
One idea might be to place the username, password and login items on a uiView with a clearBackground and then create a constraint for that view and its superview and create an outlet to it. You could then detect which phone you are using in code and modify the constraints programatically in willLayoutSubviews.
if ((int)[[UIScreen mainScreen] bounds].size.height == 736)
{
// This is iPhone 6+ screen
myConstraint.constant = 150;
} else if ((int)[[UIScreen mainScreen] bounds].size.height == 568) {
// This is iPhone 5s screen
frameRateLabelHeightConstraint.constant = 100;
}
There will be a better way to do this in Autolayout no doubt but I do find it a bit confusing so I have used this method in the past.
Here is a sample project uploaded # One Drive. Here are the sample outputs on various versions of iPhone Simulators...
As I see you want to put your form to the center of view. So I think the best solution will be to put your form elements on another transparent view and add to this view centerX aligment constraint and centerY aligment constraint.
you can check another way here

Resize UITableView for iPhone 5

How can I adapt an UITableView height to iPhone 4-inch screen? I have the following configuration, which works for iPhone 4. However on iPhone 5 (see image below) there is a blank space because the tableview does not rezise. The tableview is scrollable.
I've autolaout enabled and I tried defining horizontal and vertical spacing constraints for all views and the tableview, but I get the same results (see image below). Any suggestion?
This viewcontroller is placed inside a placeholder since I created a custom menu. I tried settting the constant of the placeholder in the parent view with the following code. Also not working, the tableview is clipped.
-(void) viewDidLoad{
if([[UIScreen mainScreen] bounds].size.height == 568) //iPhone 4inch
{
NSLog(#"iphone5");
self.dynamicTVHeight.constant = 465;
[self.placeholder needsUpdateConstraints];
}
else{
NSLog(#"iphone4");
self.dynamicTVHeight.constant = 375;
[self.placeholder needsUpdateConstraints];
}
And these are the constraints of my parentview, which implements a custom navigation menu. I did two tests:
With the vertical and horizontal spacing constraints:
And with the height constraint in my placeholder:
You need to set the bottomSpaceToContainer (or Bottom layout) to 0.
Make sure that there are no warnings or errors in your nib file (indicated by the yellow or red sign on your UITableView). If there are none, make sure you have all 4 constraints needed to fully describe your UITableView's position.
What you want :
To compare iphone 4 and iphone 5 :
Hope that will help =)

Resizing a UIImageView programmatically

I have tried several different solutions to this problem with no success.
I have a UIImageView (created on the Storyboard) that has multiple Gesture Recognizers on it. I have trying to resize this UIImageView based on screen size to take advantage of the 4 inch display.
It appears that since the Imageview was built using the storyboard, I can't change it programmatically???
My current code looks like this:
//determine screen size, set scoring button width based on device size.
CGFloat lCurrentHeight = self.view.bounds.size.height;
if (lCurrentHeight == 568.0) {
CGRect _redHeadImageFrame = _redHeadImage.frame;
_redHeadImageFrame.size.width = 220;
[_redHeadImage setFrame:_redHeadImageFrame];
}
Any ideas??? Thanks.
If you are using autolayout you have to change withConstraint of the image, because manual changing of the frame will not work in this case.
EDIT
You can create IBOutlet for the width constraint as you do it for other controls - just select constraint in IB and move it with right button to your header file. Than in code change constraint:
[self.imageWidthConstraint setConstant:100.0];
yes you need to use like this,
CGFloat lCurrentHeight = [[UIScreen mainScreen] bounds].size.height; //it will give 568
CGFloat lCurrentHeight = self.view.bounds.size.height;//it will give 548,in your case that condition failed.
There's no difference in resizing UIViews created by code or by the storyboard. It's exactly the same: setting the frame of the view, as you are doing.
What might be happening:
Your if condition it's never true. Have you checked with a breakpoint if the code inside it is even called? Maybe there's some error in the float direct comparation. See this.
Also, see this for a better understanding on how to check if it's 4 inch display.
If the setFrame: code is actually called, check if you are using auto-layout in your view. Maybe there's a constraint in the UIImageView. In this case, you should play with this constraint, in order to resize the view correctly..

UIPickerView animated on bottom for both retina 3.5 and 4

Have an UIScrollView (mainScrollView) that is 838 pt height, so it's bigger than both retina 3.5 and retina 4 displays height, and the user can so scroll it down to see all content.
Want to display an animated UIPickerView from the bottom, and it should stay always on the bottom of the screen, independent of screen height (retina 3.5 or 4) or mainScrollView (838 pt) height.
Is there a way to get the "window" or "screen" height and add UIPickerView considering the measures for the different screens? What should be the correct approach to accomplish this?
This will return the frame of screen
CGRect screenFrame = [[UIScreen mainScreen] applicationFrame];
With this you can position your picker accordingly !!!

Resources