How do I set Xcode Interface Builder constraints so that views change their width or height accordingly?
I am using Xamarin Studio for iOS development and I have just started using the Xcode Interface Builder and it is giving me headaches. My Xcode version is 5.1.1 (5B1008) and I am on Xamarin Studio 5.5 build 227 with Xamarin.iOS 220.127.116.11 in starter version.
I can't figure out how to use the Auto-Layout functionality and I've read the tutorials, most of which are, say, drag an element into view, click the Pin icon, set constraints and be done with it.
But the elements I add don't look the way I want them to be.
For example, let's say I want to create a view with a scroll view in it and it will display labels and text boxes as if it were a form, dragging an element, imagine I get something like this:
I want each label and textbox to be 11 dps apart from left and right regardless of orientation, each must be 11 dps apart, with the original label being 50 dps apart from the top of the scroll.
Each element must have the same height (20 dps), but their width must change according to the left and right constraints.
This is the end of my layout definition.
Now let's start by defining the left and right constraints along with the height. I do this to select all labels and text boxes, I click left and right and set their height to the same value:
But what I get looks like this:
The resulting layout doesn't look the way I wanted, the width for each element is one size and the correct values don't make sense, I said 11 dps, but I get values like 187, 173 and 228.
Even if I set upper and lower limits, the correct limits keep the same:
How to fix it? I have uninstalled and started from scratch several times, but I cannot figure out what I am doing wrong. Some technical issues sometimes throw me (I'm not a native English speaker) so I don't know if I'm interpreting something differently.
source to share
You need to ask Interface Builder to update the frames for these elements. All of these yellow lines / numbers are constraints that are currently not enforced - element frames do not meet the requirements required by the constraints.
However, it is often best to make sure that you have all of your constraints configured in the first place before asking IB to update the frames.
This is where I set all the constraints you described, but I didn't ask IB to update the frames:
Here I asked IB to update the frames of all views in the top level view:
If I select subviews, I see that the constraints are now displayed in blue, that is, they are satisfied:
source to share