Disable Safe Area Layout Guides For UIView Programmatically

◇◆丶佛笑我妖孽 提交于 2020-01-14 08:48:06

问题


Safe area layout guides can be disabled in Interface Builder by unchecking the Use Safe Area Layout Guides. How can this be done in code?

I didn't notice an iOS11-available boolean that directly corresponds with the checkbox.


回答1:


I think the only way to accomplish this programmatically is to override the safeAreaLayoutGuide property.

override var safeAreaLayoutGuide: UILayoutGuide {
    return UILayoutGuide()
}

When you disable it through IB it still returns a UILayoutGuide but with zero layoutFrame, by returning an instance of UILayoutGuide, you are basically doing the same.




回答2:


If there is someone faced that problem while using new SwiftUI I used following to ignore safe area

Text("Hello World")
    .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
    .background(Color.blue)
    .edgesIgnoringSafeArea(.all)

edgesIgnoringSafeArea(.all) is the method that extends the view out of the safe area on the specified edges.



来源:https://stackoverflow.com/questions/47228989/disable-safe-area-layout-guides-for-uiview-programmatically

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