Reputation: 614
I'm practicing using snapkit to place ui of view. However, I tried many things to move the red box into the safe area under the notch, but I couldn't find a way.
var redView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubview(redView)
redView.backgroundColor = .red
redView.snp.makeConstraints{ make in
make.top.equalTo(view.safeAreaInsets.top)
make.size.width.height.equalTo(100)
make.left.equalTo(view.snp.left)
}
here is my code. Why doesn't it still come into the safe area even if I designate the red box tower as Safe Area Insets.top? I would appreciate it if you could let me know my mistake.
Upvotes: 6
Views: 12890
Reputation: 3722
Try this:
redView.snp.makeConstraints{ make in
make.top.equalTo(view.safeAreaLayoutGuide.snp.top)
make.size.width.height.equalTo(100)
make.left.equalTo(view.snp.left)
}
Upvotes: 21