Cannot add new alignment constraints auto layout Xcode 6 - uiscrollview

Why I cannot add new alignment constraints on my scroll view ?

In order to add alignment constraints, you must select two or more items before pressing the Align button. This is how Interface Builder knows which two objects to align. You can select the items by dragging a box around them, or you can hold down Shift and select the items.

If you are aligning to centre horizontally/vertically (which doesn't require a second view for reference) and still get this issue, then go to the size inspector (ruler icon in the top right navbar) and change the layout dropdown to Automatic.
This should then enable values and the button in the alignment constraints dialog.

Related

How to make NSSearchField take up whole width of toolbar

I am trying to make a NSSearchField taking up the whole width of a toolbar in a NSWindowController.
I created a new NSWindowController using Xcode storyboard, add a toolbar to it, when add search field to the toolbar.
I drag the search field from allowed toolbar items to default toolbar items
Set toolbar item's max width to a large number say 1000
I build the app and run. The search field shrinks when window width shrinks, but does not expand beyond a certain width when window width expands.
The question is how to make search field expand and take up all remaining space of the toolbar?
It doesn't sound to me like the toolbar is really what you want to use here. The purpose of the toolbar is to allow multiple UI elements to be included in a user-configurable way. If you want to force one element that takes up the entire width, I suggest just putting it in the window's content view and setting up the layout constraints to pin to both the left and right sides. If you set the "Textured" check box in Interface Builder, it should look roughly the same as it would have looked using the toolbar.

Autoalign changes width of my button

I'm setting width for my button so that it's greater than text size - as on image below:
The width of it is 120px. My problem is that I have center vertical alignment for it so when I hit "update frames" then my button gets resized to it's minimum so that text fits the button as below:
I can't leave it that way because I've added frame programatically and it looks bad when it's so close to the text.
Is there any way to set some properties for xcode to stick to my width as oppose to auto-align it? I'd prefer to have it in xcode properties than in swift code.
You are not adding a constraint to the width. You need to add a constraint to it, not change de width at the Size Inspector.
Select the element, click at the Pin option at the bottom bar, and set the width of your element. Update Frames and voilà.
Remember: when working with Auto Layout you cannot use any manual configuration (size, position, etc.) for that element, always use constraints or stack views.
Apple documentation about Auto Layout

"Add New Constraints" checkboxes and fields are disabled

I have a project I am upgrading from Xcode 4.6.3 to Xcode 6.1.1. I opened it in Xcode 6.1.1, and opened each .xib. The format of each .xib changed as expected. I want to attempt to use auto layout. Use Auto Layout is checked and so is Use Size Classes. I changed every appropriate object from Alignment Frame to be Alignment Rectangle.
For a while I couldn’t add any constraints. Then after some trying I could add a few. See the screenshot.
For the selected View, I cannot add a constraint. The Add New Constraints checkboxes and fields are disabled. Only Update Frames is available to be changed. I can’t add an alignment constraint either. Ctrl-drag a line off the view does not add a constraint either. Notice the View height of 411. If I select another object, then select the View again the height will change to be the height of the parent tab bar less. If I keep doing that the height gets smaller and smaller, then Xcode crashes. How can I add a constraint to this view?
The Tab Bar X, Y, Width, and Height are disabled. When I change the Height of the Assigned View Controller View, the Tab Bar Y changes to that value minus the Tab Bar Height of 49. When I select the View, again it’s Height is now 49 less. Select the Tab Bar, it’s Y is now 49 less. And so on. How do I set the dimensions of the Assigned View Controller View that will stick when I cannot add contraints?
I had the same issue. In my case, the view layout setting was set to Translate Mask Into Constraint. I resolved it by changing it to Automatic in Size Inspector.
Xcode 12, Xcode 13
For UI elements where adding constraints are disabled, check Layout in the Size Inspector:
If Layout is set to Autoresizing Mask change to Inferred.
or
Inferred(Constraints) - The UI element already has one or more constraints.
Inferred(Autoresizing Mask) - The UI element currently has no constraints.
Steps to enable autolayouts:
Select any UI element, in storyboard.
Click on Show the Size Inspector.
Click on dropdown beside Layout option, select Automatic from dropdown.
Zev has the answer. You can't add constraints directly to the top-level view in a view controller.
In regards to the height of the View decreasing when selecting it, I started over from the original .xib making small changes and taking notes. When I checked "Use Auto Layout" and "User Size Classes", got alert the document will no longer be compatible with Xcode 5. Window frame size went from 320 568 to 600 600. ibExternalTranslatesAutoresizingMaskIntoConstraints went from 1 to 0. Other changes apparent as well. Adding constraints to objects contained in View one at a time I am getting good results. The behavior of the View height decreasing when I select it is gone.
Trick to enable constraints on the root view:
Inside the xib, drag a new view that will be sibling to the initial root
view.
Move the initial root view inside the sibling view. It will be
able to have own constraints.
Move the initial view back to be a
root.
Delete the empty sibling view.
Xcode 12 Swift 5
Select the UI Control and click on Show Size Inspector window
Change Layout option to Inferred (Autoresizing Mask))
By default the Xcode 12 keep the setting of layout to Autoresizing Mask, If you want to apply the constraint used Inferred

Can't align label on a Segmented Control in an NSToolbar

As you can see from the screenshot, the View button text is aligned properly under Allowed Toolbar Items, but once I add it to the toolbar, it's aligned to the right. Why?
You have to set sane minimum and maximum sizes for the toolbar item. I think you also have to make sure the autoresize masks (or constraints if you're using automatic layout) are set properly in the toolbar item's view (the NSSegmentedControl in this case). I don't have the "proper" settings handy but the min/max toolbar item size + correct autosizing behavior are the key here.

How to assign different z-order to my Interface Builder objects?

How can I change the z-value, or just send to back or to front the objects in Interface Builder?
i.e. I would like to move to front the "Label" in this View:
You need to reorder then in Interface Builder. It seems like you're using Xcode 4. So, first, click on the arrow in the bottom left corner of IB to expand the side panel:
Next, click and drag the views that you'd like to rearrange.
The lower an item is on the list from the top of the list, the higher its "z-index".
with that object selected, goto (menu) Editor>Arrangement> . There will be 4 options with activated appropriate options.
xCode 10.3 (2019):
I had the same problem when copying/pasting a background image view. I couldn't drag it to change its z-order in the Document Outline panel (in Interface Builder).
The answer was just to restart xCode.
I think that re-indexed/re-built the storyboard and I could drag it higher in the list (thus making it lower in the z-order + behind the other controls).

Resources