接口构建器中的UIView`readableContentGuide`? [英] UIView `readableContentGuide` in Interface Builder?
问题描述
iOS 9 readableContentGuide
是所有UIView都具有的UILayoutGuide(本质上是可以将约束固定在上面的东西).这样做的目的是避免在iPad上横向放置带有文字的子视图.
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.
很容易在代码中进行配置(v1
是子视图,v
是其子视图):
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)
])
现在.到目前为止,一切都很好.但是...在两个不同的WWDC视频中,非常明确地声称您可以在Interface Builder中配置将子视图固定到其父视图的readableContentGuide
.
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?
推荐答案
像往常一样将子视图的边缘固定在超级视图的边缘.
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:
这篇关于接口构建器中的UIView`readableContentGuide`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!