Yes, do it programmatically.
Create a constraint relative to top of safe area.
Create an IBOutlet for the constraint (control-drag from constraint to ViewController) : topConstraint
In viewWillLayoutSubviews, compute the correct value and set it:
// To get screensize:
func getScreenSize() -> (height: CGFloat, width: CGFloat, topPadding: CGFloat, bottomPadding: CGFloat) {
// Get the screen width and height.
let screenWidth = UIScreen.main.bounds.size.width
var screenHeight = UIScreen.main.bounds.size.height
var topPadding = CGFloat(0)
var bottomPadding = CGFloat(0)
if #available(iOS 11.0, *) {
if let window = UIApplication.shared.keyWindow {
topPadding = window.safeAreaInsets.top
bottomPadding = window.safeAreaInsets.bottom
if (topPadding > 0 && bottomPadding > 0) {
screenHeight -= topPadding
}
}
}
return (screenHeight, screenWidth, topPadding, bottomPadding)
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
let screenHeight = getScreenSize().height
topConstraint.constant = 2 * screenHeight / 3 // 2/3 from top ; for 1/3 from top topConstraint.constant = screenHeight / 3
}