Auto layout sticking to wrong side - xcode

I have a checkbox that is sticking to the left side of the view. I want it to stick next to the controls to it's right or the same distance from the right side of the view. How do I do that in Xcode (IB)?

Editor -> Pin -> Trailing Space to Superview
Then I can delete the bad "Leading Space to Superview"

Related

How to fix "Scrollable Content Size Ambiguity" in Xcode 11 (iOS 12, iOS 13) using Auto Layout

When using Auto Layout, I am unable to set up a simple UIScrollView in my view controller in Xcode 11 beta. I know that I must constrain the scroll view to the edges, and then set the scroll view width and height equal to the width and height of the entire view that contains the scroll view. However, I am not getting the option to set equal widths and heights when I attempt to do so.
When I do the right-click-drag from the scroll view to the entire main view, I get the following options:
Leading Space to Safe Area
Top Space to Safe Area
Trailing Space to Safe Area
Bottom Space to Safe Area
Center Horizontally in Safe Area
Center Vertically in Safe Area
In other videos, there is an "Equal Widths" and "Equal Heights" option that I don't seem to have.
Am I doing something wrong, or did Apple change the way scroll views work in Xcode 11?
Disabling the content layout guides in the size inspector (ruler icon) in properties
I was having the same issue, and by disabling the option it was gone.
I stacked with that problem as well.
Found a good guide that helped me:
https://useyourloaf.com/blog/scroll-view-layouts-with-interface-builder/
Basically what you need is 9 constraints (assuming you want to scroll only vertically):
1-4: ScrollView to Superview (top, bottom, leading, trailing). Make sure to connect it to parent view and not to safe area.
5-8: Content view to Content Layout guide (top, bottom, leading, trailing).
Content view Width equals width to Frame Layout Guide.
I also encountered this problem (Version 11.0 beta 3 (11M362v)). I solved this problem by first setting the layout in xcode10 and then running it in xcode11. I haven't found any official instructions yet, proving that this is a problem with xcode11, but for now, I guess this is a problem with xcode11 bate.
After spending a long time on this scrolling issue in Xcode-11. The conclusion on this issue is you have to choose the scrolling option while adding a new constraint.
You can refer to the following screenshot to resolve your issue.
These mentioned solutions worked for me.
Disabling the content layout guides in properties worked for me.
Well, I was facing this issue but I have found a solution.
Problem is the Safe Area.
Embed Scroll view in a UIview.
give Top, Bottom, Right and Left 0.
now give constraints of scroll view with this view.
Add Equal height and width of content view to this View.
parent view is automatically giving Safe Area. All you have to do is just embed your scroll view in a UIview and then give equal height and equal width of the content view to this view.
#Vadim's answer worked with a little adjustment.
Nothing else worked and I didn't want to disable 'Content layout guide'. Since apple enabled it, why disable it. So there must be something I'm missing or it's a bug.
Vadim's answer is:
I stacked with that problem as well. Found a good guide that helped me:
https://useyourloaf.com/blog/scroll-view-layouts-with-interface-builder/
Basically what you need is 9 constraints (assuming you want to scroll only vertically):
1-4: ScrollView to Superview (top, bottom, leading, trailing). Make sure to connect it to parent view and not to safe area.
5-8: Content view to Content Layout guide (top, bottom, leading, trailing)
9: Content view Width equals width to Frame Layout Guide.
All good, but it didn't work,
But then I realize that the above 6 and 8 (trailing and bottom constraints to 'Content Layout guide') constraints are a little weird. They had positive constant values instead of zero. Like the below image. (constant equals to width and height of the scroll view). I changed them to zero and now it all works.
For me, initially the Content Layout Guides is in disabled state by default in ScrollView. So I just enabled and disabled the Content Layout Guides then the error disappeared automatically.
Xcode 11+, Swift 5.
I solved my issue, I prepared video and code

Silence "Views without any layout constraints may clip their content" on a specific view controller that has preferredContentSize set

I have a view controller that's fixed size (it can not be resized). This specific view controller is presented as a sheet in a window, I disabled the resizing by setting preferredContentSize. Since it can't be resized anymore, I left the view without any constraint. However, when I build the app, I got a lot of warnings that says :
Views without any layout constraints may clip their content or overlap other views.
I do know that if you don't add any constraints in a standard window it will clip when it is resized. However, resizing is disabled on my specific window so that I know it won't happen. Is there a way to silence this warning? There are a lot of views on this specific view controller and it's blocking other useful warnings that I may encounter in the issues navigator.
This view controller is presented through a "Sheet" segue.
I had a single warning saying the same thing.
Editor > Resolve Auto Layout Issues > Add Missing Constraints
worked for me.
If it doesn't for you, something else under "Resolve Auto Layout Issues" might work.
For me what worked was the reposition the elements: Drag them again into position and drag their height and width to the desired size again. Then click on "Resolve Auto Layout Issues" and click on "Reset to Suggested Constraints".
Since no one answered this, here is how I fixed it. For each view on the form change the Layout option from Automatic to "Translates Mask Into Contraints". If you want it anchored to the upper left corner, select the top an left red handles and leave the lower and right unchecked.
For me what worked was; select the last element that cause the warning
size inspector tab > layout > Autoresizing Mask

Auto Layout view resizing frustrations when designing in Interface Builder

Problem: UIView size is "locked" when designing with Auto Layout in IB
I've uploaded a 20 second video that illustrates my problem, but let me describe it. You may recognize the project: it's right out of Apple's WWDC 2012 "Introduction to Auto Layout." I've got a simple iPhone view in Interface Builder where I've already got a button and label along the bottom. The next step is to add a UIView. Here's where things get ugly.
When I drag the UIView out of the palette in Interface Builder and onto the iPhone window, as soon as I let it go it seems to become locked in to its starting size. I place it in the upper left corner, and I'd like to drag it horizontally to the right side of the window, and vertically to where it will be up against (minus the padding) the button and label along the bottom. But, when I try to resize it, I cannot. It's stuck on its original size!
The video illustrating my problem is here:
http://www.youtube.com/watch?v=jsW4UwnCEkw
You can see me grab the right edge of the view and try to pull it along to the right side of the window, but it won't expand. You can then see me move the entire view to the right side (it retains its size) and then try the opposite: grabbing the left side and trying to expand it so that it sizes up against the left side of the window. In both cases, the view is simply locked to its original size.
What gives! Auto Layout in Interface Builder is just the most frustrating thing. How do I resize a view by dragging? Thanks!
(Note: Xcode 4.6.3.)
In IB, in the series of buttons in the lower right hand corner, click on the rightmost button:
When you do, you'll see a "When resizing Views Apply Constraints To..." pop-up menu:
Make sure that "Siblings and Ancestors" is not checked.

Unexpected behavior using Autolayout with NSSplitView

I have the following implemented with springs and struts along with several NSSplitViewDelegate resizing and constraint methods and it all works as desired. I am now trying to adopt autolayout for this same scenario by replacing all of the setFrame messages and NSSplitViewDelegate methods with proper autolayout constraints.
My main window's view contains a vertical split view (I call OuterSplitter) with the top, bottom, left and right leading and trailing space constraints set to zero for OuterSplitter to its superview.
The right pane of OuterSplitter contains (among a few other things) another vertical split view (I call InnerSplitter) which also has the top, bottom, left and right leading and trailing space constraints set to zero for InnerSplitter to its superview (i.e. OuterSplitter's right pane).
I have set nominal minimum width constraints for OuterSplitter's left pane, and also for both the left and right panes of InnerSplitter.
When the main window is being resized, the desired behavior is for all (or most) of the expansion and contraction to be applied to InnerSplitter's left pane, unless one of the minimum width constraints takes effect. Therefore, I have set the split view Holding Priority for OuterSplitter's left pane to 260 (highest) and 250 for the right pane. Also, the Holding Priority for InnerSplitter's left pane to 245 (lowest) and 255 for the right pane.
I have watched the video for session 232 from WWDC 2012 and thought I was on the right track. My autolayout constraints work mostly as desired, but there is one very strange behavior that does not occur with my springs and struts version.
If the split bar of the InnerSplitter is as far right as it will go (InnerSplitter right pane is at its minimum size) AND the OuterSplitter split bar is NOT as far left as it can go, then if you try to drag InnerSplitter's splitter bar farther to the right, then unexpectedly the OuterSplitter's split bar moves to the left causing the InnerSplitter's Left pane to grow and OuterSplitter's left pane to shrink. My expectation is that no resizing should take place in that case.
It is possible to stop the OuterSplitter's split bar from moving when tugging on the InnerSplitter's split bar that is pinned to the right? If so, what constraints should be added? Or are some of the NSSplitViewDelegate methods still required? Thanks.
BTW, I'm using Xcode 4.6.3 and targeting OSX 10.8.
I had the same problem and got around it by using NSViewControllers within each split view pane so that I didn't directly have split views embedded in split views. It's more code and more complex but it does seem to work.
I never found a solution for when split views are embedded in split views so I'll be interested if anyone has an answer.
To fix this, you could add an explicit width constraint on -mouseDown: in the NSSplitView before calling through to super, then remove it immediately after.
Also, it looks like this is fixed in the 10.11 beta!

Center an object between two objects with auto layout

I am laying out a calculator using Interface Builder and I ran into some issues with the layout of buttons.
I have 3 columns of number buttons, similar to most calculators, and I had no problem placing the left and right columns as the auto-layout feature of Xcode snapped them in the correct distance away from the edge of the window on the left and the operator buttons on the right; however, there was no automatic help for centering the middle column of buttons between those two.
I can eyeball it pretty well but I really prefer to have everything perfectly aligned. Is there any way to center a button between two other UI objects like this? here is a picture of the layout:
You can place all the buttons in their own View. Place the view where you want the buttons. Then you could align the left buttons to the left of the view, align the right buttons to the right of the view, and finally center the middle buttons. Then adjust your view you made accordingly. I did something very similar. Hope this helps.

Resources