Buttons well displayed in IB but not in simulator - ios

I'm adjusting buttons like this in IB:
However, when running I have this(B is in above A) :
When I disable auto layout, I have the expected results, however, I'm having other problems with other views. Is there any solution other than disabling auto layout?
Thank you very much.

Your constraints are the problem. Try to get rid of constraints that are making the button aligned from the bottom. Then apply the 3.5 form factor in the IB to see if it works. Just ask if you need more clarification.
Edit: A tip is that if you can't delete the constraints from the menu, you can go to the document outline and manually delete it.

Check if Auto Layout is enabled.
If Interface Builder is using 3.5" layout, and your simulator is iPhone 5 ( 4" layout ), you have to adjust the Auto Layout constraints to fit the 4" layout.

Related

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!

Autolayout views always same size on different screen sizes

I have a view:
Can someone help me to layout these views that they all look the same on every iPhone? I mean size is dynamic and views shrink according to screen size.
I have tried aspect ration and other layout options but none helped.
if you want to change the view sizes on different screens using auto layout ,you have to add the height and width constraints .then only it changes view size.
Steps:
open your project in xcode.
goto storyboard choose Auto layout ,select your view ,
in Xcode From the Editor menu, choose Pin\Width and Height both
http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1
As per your question please look at the link below it might help solving your problem of multiple views size and layout.
https://stackoverflow.com/a/27471120/4101371
you can also refer:
https://www.youtube.com/watch?v=Nl2iMF0yKW8&list=PLXCowKcXAVgrxHKLWTa4HxNPrSmTj3D-_
I've also added this link in the answer in above answer.

Button At Center of iPhone 3.5 and iPhone 4 inch using AutoLayout?

I have simply Drag and button and set Image on it as following
Yet I have not used any CONSTRAINTS. As I run on iPhone 3.5 inch, it shows like below, where Button goes slightly down towards Y-Axis.
I have TWO Questions here to ask.
1. Which Constraints should I add to this Button?
2. Why these constraints are added, Simply I want to know Formula for calculating it.
I would be thankful, If someone comprehensively describe my questions.
Thanks
Question 1:
This should be pretty easy in IB, using the Alignment Constraints dialog. Click the button, and in the Alignment Constraints, check Horizontal Center in Container and Vertical Center in Container. In the below collage, you can see how this centers the button on both 3.5 and 4 inch displays.
(Don't forget to click the button "Add 2 constraints" :-) )
Question 2:
Not sure what you are after... Formula?
select button
click resolve autolayout issues (bottom right)
add missing constraints
Question 1 & 2:
It is depends on your requirement and layout design.
adding constraints for alignment or spacing, you can also use this menu to resolve layout issues, and determine constraint resizing behavior.
Align. Create alignment constraints, such as centering a view in its
container, or aligning the left edges of two views.
Pin. Create spacing constraints, such as defining the height of a
view, or specifying its horizontal distance from another view.
Issues. Resolve layout issues by adding or resetting constraints
based on suggestions (see “Resolving Auto Layout Issues”).
Resizing. Specify how resizing affects constraints .
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/AutolayoutPG/WorkingwithConstraints/WorkingwithConstraints.html#//apple_ref/doc/uid/TP40010853-CH8-SW1

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

Layout messed up on iPhone 5

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

Resources