Layout messed up on iPhone 5 - ios

I use MainWindow.xib for the layout of my app. I set everything on the view controller attributes simulated metrics to iPhone 3.5 retina. There is no image set for the iPhone 5 Default, yet it still tries to run the app full screen on an iPhone 5, causing the screen to be all out of sorts. Any thoughts on fixing this?
Here is on 3.5" screen:
Here is on 4" screen:

You need the constraints on your labels and fields to be connected to the top of the view, not the bottom. By default, IB pins things to the closest edge. Use the pinning menu to achieve this, then delete the constraints that connect them to the bottom.
Alternatively you can switch to the 4" layout in IB and set things up there.
I have written about editing constraints in interface builder here, hopefully that will be useful to you.

As for fullscreen mode, I think Xcode will put -568.png image for you, you might want to check?
As for fixing the layout, it seems that all you need is to fix top strut on all text fields, so the top position is always the same.

set UITextField autoresizingMask to UIViewAutoresizingFlexibleBottomMargin
recipientLabel.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
nameLabel.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
...

Related

Why my iPhone 6 screen resolution get differs?

In my app, I have a condition to display a UIView in my view controllers if that view appears on the screen the iPhone 6 have the iPhone 5 resolution if that same view isn't appears there is no issue. I've calculated the screen resolution via code and test the above scenario. I think that Auto layout will change the screen resolution. Please help me to fix it. Also please share factors that changed the screen resolution.
Select your View Controller, go to Attributes Inspector of the Utility Area and please ensure that you chose Inferred in Size
Enabling AutoLayout alone will not change your view's size.
You should add constraints to it.
Once you are done, You need to set constraints for your view.

Why do the layout positions change in preview when I simply add a new screen size to the preview screen?

I have a 4 inch screen displayed in Assistant Editor Preview while I'm adding constraints to the view controller in Storyboard. Once I get everything situated in the correct position with the constraints and the layout looks good on the 4 inch screen, I then add another screen size to the preview window. For some reason, just by adding another screen size to the Preview window causes the layout preview on my perfectly good 4 inch screen to slightly be changed. Is this odd behavior or am I doing something wrong?
I had a similar issue, but instead with the 4.7 inch screen size. I found that using 2 things helped me keep the layout and constraints consistent across all screen sizes.
First, keep your storyboard default layout to universal (square) so the constraints aren't applied to one screen size only.
Second, when setting your constraints, use the "Reset to suggested constraints" button located on the third constraints tab.
I have yet to experience layout issues using this method. Hope this helps!

Issue displaying uitableview in UIViewController - Not aligned

I dragged a uitableview component to my UIViewController in the Storyboard.
It appears as
Then when I ran the application, there's a space on the side. How to prevent this?
Note: Initially this application was enabled autoLayout, and I removed it later on. Hope there's no effect for this error.
Add constraints on your tableview.
If you don't know how to, here is a simple step by step :
Right clic or ctrl+drag the tableview (on the left side list) to
View.
Select Top space to top layout guide Repeat with Bottom
space to bottom layout guide
Repeat with Leading space to
container margin
Repeat with Trailing space to container margin
That should fix your issues.
The answer on this link will surely help you.
https://stackoverflow.com/a/26708486/3396270
Though its Table view in your case you can use it with all the components by changing the settings as per their requirements.
Check your screen size in Storyboard:
And make sure you are running the application on same size of Simulator as in your storyboard.
If you uncheck the Translucent property of your Navigation Bar, it's going to fix it.
If you are not using AutoLayout then just write this code in your viewDidLoad Method
[tableView setAutoresizingMask:UIViewAutoresizingMaskFlexibleWidth | UIViewAutoresizingMaskFlexibleHeight];
You could also set the AutoresizingMask from your nib file.
What version of the xcode are you using? If it's okay with 5s and not okay with 6 and 6+ then you should change the size of the table manually or use autolayout. Storyboard which you'v used should have optimised for devices below 6. I you're using #3x image for splash screen then your app supports 6 and 6+ but it uses the same table size as what it is designed for 5s device size on simulator.
Solutions-
Use auto layout so this will solve the issue itself.
Else create outlet for table and changes it size according to the device width and height.
I have released an app using the above 2 solutions and its in the store now.

UIButtons not working on certain devices

I've set up a view and constraints using the wAny hAny layout in Xcode 6:
When I run the app on a iPhone 5s and iPhone 6 the UI Elements are all visible but on the 5s the answer and the back buttons do not work - they do nothing.
On the iPhone 6 all the buttons work.
Here's the code for the `back' button:
- (IBAction)backFromDivision:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
The answer code is a bit longer and I won't post it unless necessary.
Does this have something to do with the constraints or should I be looking for answers elsewhere?
Well,
I clicked on "Resolve Auto Layout Issues" - "Reset to suggested constraints" (third from the left):
and that "solved" my problem. Everything is working on all devices. It seems to have removed some constraints that I put in place.
I'm going to have to learn more about why this worked.
I've had a similar issue before. It was the constraints that were the issue and the fact that the button was not in the view's bounds.
I've encountered this issue, and the problem was due to the button having:
buttonView.frame.height = 0. (it can also happen with width)
The problem is that even with no height the button text appears on screen so if you don't have a background the button visual appearance does not change.
To resolve this issue I played with the views Content Compression Resistance Priority(CCRP) of different views to chose which view should resize on smaller screen.
The default CCRP of views is 750, default contraint priority is 1000.
So to match your constraint ios may resize the height of your views

iOS 7 keep buttons at bottom in 3.5inch and 4inch

I haven't done iOS development in a while (since Xcode 4 and iOS 5). And I have a very noobish question:
How can I keep buttons at the bottom of a storyboard viewcontroller on both 3.5inch and 4 inch devices? Previously I could use 'origin' or something similar in the right side panel.
A quick solution, especially if you don't need to deal with rotation of elements much is to add some basic auto layout constraints to your view.
Once you have your button set in place in your view where you want it to stay in the view, select your View in the Storyboard and then from the Menu Select Editor -> Resolve Auto Layout Constraints -> Add Missing Constraints in View.
Simply doing that will give you what you want. Make sure you have auto layout enabled for your storyboard.
set autoresizing mask as shown in image to keep button at buttom in both 3.5 and 4.
i think you are using autolayout so apply first approach
with AutoLayout. add constrains for your widgets
without AutoLayout

Resources