There are many guides out there that talk about auto-layout such as: http://www.raywenderlich.com/83129/beginning-auto-layout-tutorial-swift-part-1
Now constraints don't seem to be super complicated except that when it comes to trying to set them on a UIImageView within a ViewController, With "Use Auto-Layout" ticked, I can't for the life of me set any constraints as when I click any of the three buttons used to achieve this, all the options for setting constraints is greyed out.
I'm sure this is something simple... little help?
I've found something in reference materials: "Constraint options that require multiple elements are disabled if you have only a single element selected." but in none of the guides do I have to have more than the UIImageView selected to set constraints.
Edit: added images:
If you want to remove one constraint, just select it and press delete key in keyboard. If you want to edit one constraint value, just select it, and then edit it in Attributes Inspector pane ( How To Display Xcode Library, Assistant Editor, Inspectors Window ) at Xcode project right side.
How To Use Swift Constraints To Constrain UI Component. There is an auto-layout menu bar at the right side of the View as device simulator icon list, it provides five buttons for you to constrain UI components or align multiple UI components. Below are the steps about how to use it.
You have two methods to add constraints to it. Select the above button, click the Add New Constraints icon ( ) on the above auto-layout menu bar. Then it will popup the Add New Constraints dialog where you can specify the button constraints value in it.
Add a UI component ( a button ) to the Main.storyboard scene. Change button background color to green and button text color to red, also change the button text font. You have two methods to add constraints to it. Select the above button, click the Add New Constraints icon ( ) on the above auto-layout menu bar.
In my case, Xcode 11.2 somehow set layout property of my UIButton
tranlates mask into constraints
. So I changed it to automatic
from size inspector and it is fixed.
This is because you remove root view from view controller. When you add UIViewController to storyboard you can see this:
If you delete this view and add UIImageView you see this:
So add UIView as root and UIImageView as single subview of root view. And then you can play with constraints:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With