I've spent many days trying to find out, why I had quite random autoLayout constraints errors on iOS 7 (no problems on iOS 8 whatsoever).
Now it seems to me the problem could be when using custom fonts:
UILabel with a custom font inside a container and pinned to the container with 0-0-0-0 (top, left, right, bottom)
Autolayout-constraints error was always about some vertical alignment issues.
So am I right about my assumption (NOTE: no issues on iOS 8)?
Related
UIView on IPhone plus stretched and normal on regular sized iPhone. Constraints are all done in story board. I’m not sure what I’m doing wrong. Please help. Attached are imaged of the views : iPhone 7 Plus and iPhone 7.
I figured my issue was with my misunderstanding of auto layout, which is why I was not able to get my uiview to adjust properly across different screen sizes. This tutorial on youtube really broke down auto layout in such a simple way. Check it out (link below). I hope it helps someone else out there. thanks!
"Auto Layout Tutorial in Xcode with Swift for iOS 11 | iOS Development Tutorial"
Your problem is in the bottom constraint because of different screen heights you get different height for the view as the bottom constraint is static (528) , so to fix that remove that constraint and give it a static height or proportional to screen height
Also remove one of the top constraints as setting 1 is enough
I have added a 'Help' button onto my map view as shown below.
When I open it in the simulator in (iPhone 7 mode) the button appears and performs a segue properly. I changed the operating iOS to 9.3 and tested it on a real iPhone 6 running 9.3 and the button functioned properly. However, I have tested it on a real iPhone 6 running 10.0 and the button does not appear.
I thought this could be to do with auto layout but it appears fine in storyboard, simulator and the real device.
I have attached a photo of my constraints for the button below.
Any thoughts?
This may not solve your immediate problem, but you should apply as many constraints to satisfy the auto layout engine and no more. Adding more constraints may not cause conflicts on devices of the same size, but will cause conflicts on devices of different sizes causing the layout engine to have to make decisions about which to break. Often it makes choices that you wouldn't. You can check your console to see if the layout engine is breaking constraints.
If you want the button in the bottom-right corner, you only need two constraints: trailing and bottom. UIButton's have an intrinsic content size, so if you have a static title, you do not need to worry about width or height. You should remove your other constraints.
You can delete all the constraints and use only 20 to the bottom and 20 to the right (trailing) to place it nicely there.
You can play with the numbers but the main idea is that you don't need to over complicate it with too many constraints.
I made a simple screen in Xcode 7 containing a single UIImageView. Then I set its constraints (as shown in the screenshot). But Xcode still suggesting to change UIImageView's Leading and Trailing constraints. I am not sure what is it that I am doing wrong here because this kind of error did NOT happened in Xcode 6.4
For example: I have set in a storyboard scene a vertical space constraint from de bottom of a UIButton to the bottom of the superview with a constant of 20. When running in an iOS 8 device, this is correctly shown, but when running in an iOS 7 device, it looks like this constant becomes higher and the button is shown upper in the screen... I don't understand why this happens, since autolayout is supposed to be available since iOS 7.
Any help? I don`t know how to handle this.
Thanks in advance
One of new things in iOS 8 is the Layout Margin. Layout Margin is a new property available in UIView for iOS 8. So, any objects inherit from UIView will have this property. If you are developing the app for both iOS 7 and iOS 8, you should not use Layout Margin (or use layout margin in a smart way).
So, if you have any constraints related to layout margin and you didn’t do a proper check before launching the app on iOS 7 devices, the app might crash or the arrangement of the objects might be out of order.
Whenever you are trying to add new constraints from the storyboard in XCode 6, “Constrain to Margins” is ticked by default. The meaning of this selection is to add constraints with the new property in iOS 8.
If the deployment target of your app is iOS 7 and above and any of your constraints have this layout margin, the XCode will complain with the warning “Layout attributes relative to the layout margin on iOS prior to 8.0″.
If you are developing the app for both iOS 7 and 8, it is best to “Untick” the Constrain to Margins.
Reference: you should also check this great tutorial
This question already has answers here:
Layout issue, Autolayout enabled but doesn't seem to work
(2 answers)
Closed 8 years ago.
I'm working on a uikit app on Xcode 6. I created the project as a universal app, and when I'm putting labels/ui-'stuff' on the storyboard, I'm using the blue guides.
I have the use auto layout and use size classes both checked. When I'm building my app and running in iphone6/5 simulators, the labels that I have centered are not showing up centered.
also, I have wAny and hAny in the storyboard on the bottom
is there some option I'm missing?
The "blue guides" have nothing to do with anything. The problem is that you have auto layout checked but you are not using it. You must make constraints to position your interface objects relative to the size of the superview, which will grow or shrink depending on the size of the screen. If you want something to end up centered, use a centering constraint. It doesn't matter at all how it looks in Xcode; only the constraints matter.