iOS layout woes - on 4s, the bottom button is unhittable - ios

I'm making an app that supports 4s through to iPad (portrait only).
One view controller is set out roughly like this with these constraints:
http://i.stack.imgur.com/7tNlJ.png
The third button at the bottom when I launch on iPhone 4s can't be tapped.
Anyone have any idea why this might be?

I believe your problem is the bottom constraint of 128 pt on your bottom view. You should let your buttons drive the size of your bottom view. To do this, remove all constraints on the bottom view except for the align center to superview one.
Then, have your first and third buttons be tied to their superview through a top and bottom constraint respectively.
Also, have your first button be tied to it's superview with a leading and trailing constraints.
Finally, make sure all buttons have width and height constraints. And also, the second button should be tied to your first and last buttons, through top and bottom constraints, of course.

Related

Xcode 8 constraint help required

I am new to IOS development and have the attached screen that I am developing in portrait mode only. I have fiddled around with constraints for half of today but not really got anywhere with making this work on anything other than a 5s.
Not sure if i constrain to edge of phone and/or the box at the side of the one i am trying to constrain or both!
It would be much appreciated if someone could point me in the right direction to get this to fit on all screen sizes. Landscape I think is a pipe dream at this stage:)
Here are the width constraints you should add to each button:
add a equal widths constraint for each button to the main view, then set it's multiplier to 0.5. That will make each button half the width of the screen.
for the dark blue buttons, make a leading constraint to the left edge of the view (not the margin) and set it's constant to 0.
for the light blue buttons, make a trailing constraint to the right edge of the view (not the margin) and set it's constant to 0.
For the Y positioning, you should do the following:
for the top buttons, add a vertical spacing constraint from the buttons to the title view, with the constant set to whatever you want
for each button that follows underneath, add a vertical spacing constraint to the button above it with a constant of 0
for the bottom buttons, and a vertical spacing constraint to the bottom layout guide with a constant of 0
This will adjust the height of the buttons to match the screen size / orientation while maintaining your layout. should work fine with landscape, although those buttons will be awfully skinny!

Scroll View Size not match with the device screen in xcode

Ok, I tried the page with several buttons but all of them will not fit in one screen. So, I create the scroll view and the view and then put all of buttons inside the view. The storyboard look fine. Other devices such as iPhone 5 and 5S look fine but when I tried 6 and 6 plus, the size of scroll view was incorrect. I couldn't figure what went wrong.
You have to modify constraint for
scrollview with uncheck constraint to margin with all left right
bottom and top is zero
Container view to super view set equel width constraint
container view to scrollview set horizontal center constraint.
Each UIBUtton set top/left/bottom with constant height not set bottom constraint.

AutoLayout correct positioning of button

I have a view with a UIButton on it. I've added two constraints:
Leading space to superview of 16
Top space to top layout of 265
Depending on which device I look, the button is in different locations. The only way that I can get it consistent is to center it. As a result, I've been building views off of a centered subview by setting vertical and horizontal distance.
I know that these constraints are actual number values and that the different iOS devices have different screen sizes. How can I set it up so that the button will appear in the same location, relative to each device's screen size? For instance, if I have a button positioned a quarter of the way down the screen, how can I ensure that the button shows up a quarter of the way down the screen on all devices?
I feel like entire books could be written about how to set up screens with auto constraints.
A solution, without code, could be to :
Put the button in an UIView. Set the height of that view to be equal to the height of the controller's using an equal height constraint. Set the multiplier of that constraint at 3/4. Also add leading, trailing and a bottom constraints to the view. Now put your label in the view and pin it in the view with leading, trailing, top and bottom constraints. Done. If you're targeting iOS 9, use a LayoutGuide rather than UIView.
A more appropriate solution could be done with code : create an IBOutlet of the top constraint of your button in your controller. Change the constant of that IBOutlet in ViewDidLoad: method to self.view.frame.height / 4.

What constrains do I have to add to make a button scale for iPhone 4, 5, 6 and 6+

I am not a huge user of Interface Builder.
I am working with Size Classes of the kind Compact/Regular (for all iPhones portrait), right now.
I have added a button but this button is not scaling up for different sizes of iPhones.
What constraints I have to add to that button to make that button scale according to the screen?
Thanks.
If you want the button to get larger with screen size regardless or the aspect ratio of the button, add constraints for leading, trailing, top, and bottom from the button to the parent view.
If you want to maintain some aspect ratio, set constraints on leading, trailing, and top or bottom from the button to the parent view. Then set an aspect ratio constraint on the button itself.
In any case, be sure to set whatever numerical constant you want on the various constraints. Annoyingly, Xcode 6 does not seem to let you select constraints of different types and set them all at once like Xcode 5 used to. So it takes a few more clicks now.

iOS view height and auto layout

I have a viewController, which is configured for the iPhone5 screen size. In red rectangle is the view.
To make this view show properly in iPhone4 - I used auto layout. But when I specify constrains such as: leading edge, trailing edge, bottom space and top space (in top space I even made constraint's priority to LOW ) - the view still goes partially down the screen as if my constraints don't work.
BUT if instead of top space constraint I specify view's heigh and delete top space constraint - everything works perfectly.
Does anyone can explain it please? Thank you.
Thats because when you set up the top space constraint it will move the view by the constant you provided. iPhone 4 and iPhone 5 screen height is different but the constant remains the same so obviously it will behave differently. One way to troubleshoot your interfaces is to switching between iPhone4 and iPhone 5 on storyboard device on storyboard (first button from left to right on the bottom right corner of interface builder).
Auto-layout is all about experience in my opinion. I struggled alot with it until i learned. If you want your view to be attached to the bottom of the screen you should set the BOTTOM SPACE to 0 and specify the view's height like you did or adjust constraints for it's subviews so that the height is set dinamically according to the views inside.

Resources