Search code examples
swiftsnapkit

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.


Solution

  • 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)
    }