trianglejerry00
trianglejerry00

Reputation: 614

How can I lower the view into the safe area?

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.

enter image description here enter image description here

    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

Answers (1)

RTXGamer
RTXGamer

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

Related Questions