Auto Layout - Vertical spacing - xcode

I'm Ctrl dragging from one UILabel to another to set a vertical spacing and I get the following dialog:
What does this dialog mean?
How do I set a vertical spacing between the 2 UILabels using this dialog?

Apparently, you already have created a vertical spacing constraint. That's what the dot (•) next to Vertical Spacing means.
If you were starting from scratch, you would select Vertical Spacing. That would create a constraint which maintains the current vertical spacing between the labels as they are laid out on the canvas. You could then select that constraint and modify it, if you want. You can find the constraint in the document outline or you can look at the Size inspector for one of the affected views.
In general, that window lets you create one or more constraints based on the current layout of the designated views. Clicking on one of the items creates that one constraint. Shift-clicking on an item selects it and leaves the panel up so you can select more. When you've selected all that you want, click outside of the panel to create all the specified constraints.
Choosing "Left" creates a constraint relating the left (or leading) side of the views, with a constant for their current distance. Similar for "Center X" and "Right", except relating different attributes of the views.
Equal Widths creates a constraint relating the widths of the views, with a constant for the current difference in their widths. Similar for Equal Heights. Aspect Ratio creates a constraint relating the width of one to the height of the other (it makes most sense when you create a constraint from a view to itself).

Related

Set the width of a view to 50% of its container in the nib

I am creating a view with four table views in it. I want each table view to take 50% of the height and width of the containing view and to auto-resize when the window is resized.
I have been unable to find a way to do this thus far.
You should use autolayout in storyboard. Resizing and stuff like that becomes very easy that way. Basically you want to set constraints for each tableview to the edges which they are touching and their neighboring tableviews (distance: 0). Furthermore you have to set constraints for equal width and equal heights.

Letting a custom view grow with a MultiLineLabel subview

I have a simple custom view and within a Wrapping Label (Multi Line Label) as a subview. I used autolayout to set the constraints.
Now I want that the superview change its size to show all content of the wrapping label. How can I achieve that? The wrapping laben shows the content of the extra text field (Outlet: "textfeld").
You need to set the content hugging & compression resistance constraints on your label (among other constraints).
With the label selected, select the size inspector. At the bottom, you'll see the Constraints section:
These have default values of around 250 & 750. We need to boost these up to 1000. These constraints control the way that the label grows & shrinks relative to its content, but with such low priority, every other autolayout constraint you add will take priority. So we need to increase the priority of these constraints up to 1000 which marks them as required (or at a minimum, you need to increase the content compression resistance priorities).
Now you just implement other autolayout constraints around that which make sense. For example, if you always want it to have at least a 20 pixel border from each side, be 20 pixels from the top, and centered in your superview, you might set up constraints like this:
Of course, with these constraints, if the parent view isn't constrained to a max width, you won't have implicitly forced any word wrapping, so it might expand the parent view's width. We can add a max width constraint to our label too.

NSTableView: make total width of all columns always be the width of the visible portion of the table

I have a NSTableView with 2 columns. I'd like to know if there is a way to make it so that the right edge of the right column is always on the right edge of the clip view (so that it never goes beyond the clip view and horizontal scrolling isn't enabled), yet maintaining the ability to resize the two columns by moving the separator between them. This is essentially the same behavior as a split view.
I know IB offers options to control the resizing of columns, but I can't seem to enforce the rule that the total width of the two columns must be the width of the clip view (the visible portion of the table).

Resize multi-line text field

So I just returned to GUI programming after a long time on Mac OS X. I heard about this great feature called Auto Layout. For my project I want a very simple layout: a textfield dominating the window, with a couple buttons at the bottom. When I resize the window, I want the textfield to resize with it.
I thought that was simple task: constraints on the 4 edges and Height and Width >= what I have in Interface Builder:
If I set it like this, I can't resize the window vertically, only horizontally. If I drop either the Height or Width constraint, it will shrink to a tiny size in a corner.
How should I set my constraints so that the textfield resize with the window?
To resize text field with the window size you need to add constraints to all the four edges of the text field! As per your screen shot you haven't added any constraints to the right and bottom edge, instead you have added dimensions (or say height and width)!
And to avoid making text field terribly small you can add min-width and height to it.

How to have a view resize using Xcode's auto layout

I am using Xcode's auto layout feature for the first time in a project where I have several NSPopUpButtons.
Now what I want to achieve is to have two popUpButtons in a row together with their labels and when the window is resized I want both popUpButtons to adjust their width while keeping the horizontal spacing between each other.
However no matter how I apply the constraints I just don't get the popUpButtons to change their size with the window. They will always break their horizontal spacing constraints and just increase/decrease the spacing to the labels. I hope it gets a bit clearer what I have done from this screenshot:
I have set the spacings between the labels and the popUpButtons to fixed values with 1000 priority and have set the width constraints fo the popUpButtons to be greater or equal to the initial size.
How must I set my constraints to have the popUpButtons resize?
While writing this question I realized what the trick is:
In the size inspector of the NSPopUpButton I had to reduce the Content Hugging Priority.
Obviously this controls how closely the view wants to 'hug' its content. So when the hugging priority is higher than the resize priority the view will not want to increase its size because that would mean to have more empty space between its bounds and its content.
Then in my special case, I could also pin both NSPopUpButtons to have the same width and voilà: the popUpButtons will perfectly resize while keeping the spacing constant.

Resources