The iOS 9 readableContentGuide
is a UILayoutGuide (essentially, a thing you can pin constraints to) that all UIViews have. The idea is to keep subviews with text from being too wide on iPad in landscape.
It's easy to configure this in code (v1
is the subview, v
is its superview):
NSLayoutConstraint.activateConstraints([
v1.topAnchor.constraintEqualToAnchor(v.readableContentGuide.topAnchor),
v1.bottomAnchor.constraintEqualToAnchor(v.readableContentGuide.bottomAnchor),
v1.rightAnchor.constraintEqualToAnchor(v.readableContentGuide.rightAnchor),
v1.leftAnchor.constraintEqualToAnchor(v.readableContentGuide.leftAnchor)
])
Now then. So far so good. However... In two different WWDC videos, it is claimed quite explicitly that you can configure pinning a subview to its superview's readableContentGuide
in Interface Builder.
But they don't explain how you do that.
So my question is: How do you do it?
Select the items you want to align, and then click the Align tool. Interface Builder presents a popover view containing a number of possible alignments. Select the options for aligning the selected views, and click the Add Constraints button. Interface Builder creates the constraints needed to ensure those alignments.
By unchecking "constraints to margin", you are adding constraints, meaning your interface will react correctly to changes in size or orientation.
To create constraints select the button and click the Align icon in the auto layout menu. A popover menu will appear, check both “Horizontal in container” and “Vertically in container” options to center the button on the screen. Then click the “Add 2 Constraints” button. Run the application.
Pin the subview's edges to the superview's margins as usual.
Now, in the superview's Size inspector, check the Follow Readable Width checkbox:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With