I’m using the following code to position the UILabel on the screen
innerView = UIView(frame: view.bounds)
self.view.addSubview(innerView)
let headingLbl = UILabel(frame: CGRect(x: 20, y: 20, width: innerView.frame.width - 40, height: 30))
headingLbl.font = UIFont(name: "Inter-Bold", size: 20);
headingLbl.text = "What are your goals?"
headingLbl.textAlignment = .center
headingLbl.textColor = .black
innerView.addSubview(headingLbl)
Unfortunately, the UILabel gets rendered at the very top near the battery and wifi. I can’t even see it. But I’m wondering if it will render properly on different iPhones. What’s the right way to position the label? I don’t want to use AutoLayout.
See attached image.
2
Answers
Instead using CGRect(x, y, width, height) use NSLayoutConstraint.
Hope it helps
Edit: If that does not work. Get safeArea and use their’s constraint
Use safeAreaInsets
var innerView = UIView()