I have normal UIViewController on my storyboard with a standard UIView which contains only one child - UITableView
When adding constraints between UIView and UITableView ( equal widths, equla heights, vertical space 0 top layout guide, horizontal space 0 for leading margin ) as a result my table view should fill it's parent.
Instead my table view appears to have left and top margins (16 and 64). The Size Inspector shows that the table views Alignment Rectangle is as follows x=16,y=64,width=600,height=600 although all my constraints have constants set to 0's. When I try to edit manually Alignment Rectangle I keep getting Misplaced Views warnig which try to restore previous values.
Any I idea what might be the cause of this strange behaviour?
Click the view you want to remove margins. Open Contraint Editor uncheck Prefer Margin relative:
I had a very similar problem. It was solved by deselecting Under Top Bars under Extend Edges in the properties of the topmost UIViewController in storyboard.
Related
I am using autolayout in Xcode and am creating a fairly tall (1300px) ViewController with a uiscrollview to navigate up and down. I made the viewcontroller freeform so its dimensions are [375,1300]. I then incorporated the scrollview, added the content view as well as all the subviews & constrained everything, leaving no constraint errors. At runtime there are no errors, but everything is all smushed into the normal screen size when I intended for it to be very tall (~1300px) and scrollable. Any clue as to what I am doing wrong?
Below is a diagram showing the issue where:
The Outer Black Blox is the ViewController's view
The Inner Black Boxes are subviews
and The Blue Box is what is displayed on the screen
Yes, your correct #Ryan Cocuzzo. I think you need to set sub view priority from 1000 to 250. See below screen shots.
1) Select height constraint of the subview
2)Then go to show to size inspector
3) Now change the priority constraint from 1000 to 250.
4)Finally you get like this
Make sure the following are true:
The 4 content views are subviews of the UIScrollView, not your view controller.
The autolayout constraints on the 4 content views must reference the UIScrollView only, not the view controller's view.
The 4th box cannot have a bottom constraint.
It looks like the 4th box has a constraint to make it's bottom align with the bottom of the view controller's view. This would force the other views to smush up together. The 4th box also cannot have a bottom constraint so that the scrollview can resize itself to encompass it's subviews.
My table view on iPhone 7 looks like this:
I added new constraints to my table view: top, bottom, left, right 0;
and I checked horizontally in the container, too.
But on my phone (iPhone 7), like the picture shows, my table view doesn't have a vertical symmetry. Is that normal?
I also tested in a tabbed navigation controller, but the results were the same.
I didn't do anything by code. I just made a table view and added contraints...
What is the problem?
Table view separators have a 15 pixel left inset by default. If you want to change that behaviour, set Separator Insets to Custom inside the Attributes inspector and provide 0 for both values.
Moreover, your leading and trailing constraints seem to be relative to the superview's margin. Uncheck Relative to margin under the constraint's Size inspector settings.
I am trying to implement UIScrollView from Storyboard using Interface Builder. The ViewController im working on have UINavigationBar.
This is the steps i perform within my Storyboard
adding UIScrollView and set the top, bottom, left, right spacing to 0 (not to margins).
add UIView and set it to be a child of the scrollView. set its spacing to: top, left, right to 0 and it width and hight to the value listed, also set spacing to bottom of the viewcontroller.
The strange behavior is that the top constraint get way high than expected,
What am i missing here?
Thanks!
Well what you can do is select your view controller from the heirarchy on the left and in the attributes inspector uncheck "adjust scroll view insets".
I'm building a table view prototype cells defined in InterfaceBuilder, and there appears to be an 8 pixel margin below the content view in all the UITableViewCells being defined.
I'm able to align a view at the absolute bottom of a cell by setting the autolayout bottom parameter to -8, but this seems like kind of a hack and potentially brittle to future iOS updates, and it seems like there should be a way to get rid of the 8 pixel margin in IB or programmatically.
Check that you have not used a constraint which is pinned to the margin rather than the view.
If so, change the constraint to be pinned with no margin.
When you create the constraints for the outermost view there is a check box saying constrain to margin. Deselect that. On existing constraints you can also remove the margin use on the individual constraint menus for the first and second views.
When applying auto layout constraints to a UIScrollView, i´m given an error message if the scroll view is laid out to be full screen, but not if it has "margins". I´ll illustrate with 2 examples. In both examples i apply leading and trailing space to the superview and add top and bottom space to layout guide.
Example 1 (behaves as i expect.)
The auto layout constraints are blue, everything is in order
Example 2 (weird behaviour)
I stretch out the scroll view and apply the same rules as in example 1, but now 1 of the constraints ends up different. The "top space to top layout guide" is added as "Vertical space - (-548) - Top layout guide - Scroll View".
And then Xcode complains that i need "constraints for y position or height" for my scroll view.
Can anyone explain why this is?
Unfortunately, I think this is a bug in Interface Builder in Xcode 5. When you try creating a constraint from the top of a view to the top layout guide, IB usually (incorrectly) adds a constraint from the bottom of the view to the top layout guide.
To get around this, try first resizing the scrollView so the top edge of it is much lower down in your viewController:
Then try ctrl dragging from the scrollView to the viewController, and adding a constraint to the top layout guide. You can then select this constraint and adjust the constant in the inspector so that the scrollView aligns with the top of your viewController:
Alternatively, create your constraints in code :)
Just select the scroll view and manually create constraints for the top, left, bottom, and right edges.
What is happening here is that the automatically created constraints don't make sense, in that they do not fully define the size of the scroll view, only its position.
Following your original example with the scrollview smaller than the containing view I noticed that XCode was actually adding one of the constraints wrong in my case, when I selected "Top space to top layout guide" it was adding a "Bottom space to top layout guide" constraint with a large negative value. I can see something similar from your second screenshot.
My solution was to follow your example with the UIScrollView smaller than its container. I then manually dragged out the constraints, resized the UIScrollView to fit the container. The final step was to take the now correct constraints with the wrong constants and set them all to be 0.
Hope that helps, I'm still working on fixing the problem I had but I noticed this stage was similar to what you posted.