UIView `readableContentGuide` in Interface Builder?

隐身守侯 提交于 2020-06-24 22:45:09

问题


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?


回答1:


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:



来源:https://stackoverflow.com/questions/31569597/uiview-readablecontentguide-in-interface-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!