Reputation: 8914
See that 20px (pt's rather) of padding? IB does it automatically in two cases, when you hit Cmd + =
to autosize the superview to fit subview contents, and when you choose Editor > Embed In > UIView, UIScrollView etc.
.
The later is especially annoying as it takes what should be a one step time saver and turns it into a repositioning hassle that is only marginally better than doing it manually and losing the relative positioning of ALL the subviews when you drag them into a different place in the hierarchy.
Also with the Embed In
option, IB shifts the positioning of the new superview wrapper by (-20, -20) as if that makes it better...
Am I missing something here? Is there a way to prevent this padding?
Upvotes: 30
Views: 3148
Reputation: 4391
What a great news ! This is finally possible to embed views in UIView
without any tweaking thanks to Xcode 10 !
Just use the new View Without Insets
submenu.
As of now, they didn't do the same for UIScrollView
yet…
Upvotes: 6
Reputation: 21
As for now, it is not possible to do it all right. But here is what worked best for me on Xcode 9. Note that this way you will loose constraints of the top view that you are embedding. So, to embed one view into another:
That's it.
Upvotes: 0
Reputation: 19212
All you have to do, at least in Xcode 7.2 is give the Container View the following constraints
Trailing Space to Superview = -20
Leading Space to Superview = -20
Upvotes: 0
Reputation: 4823
I finally figured out how to do it, related to this answer:
Group views in Interface Builder
Now your child elements are correctly positioned within view "B", and there is no 20 pixel padding.
Tested in Xcode 4.5.
P.S. this technique can be especially useful when you wish to have a sidebar and support both 3.5" and 4" displays. You can give the sidebar and main view the appropriate autosizing and then scale subviews in relation to them. I was having trouble getting GLKit views to respect autosizing rules, so I set up ordinary views and embedded the GLKKit views within them with all of the red autosizing bars enabled:
GLKView nested subview frame size and bounds size incorrect
Upvotes: 37