问题
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