skip to Main Content

I have a button in my layout and I would like to specifically set it to SafeArea.bottom = button.bottom + 28. I am having errors when I try using

btnAddRecord.translatesAutoresizingMaskIntoConstraints = false
btnAddRecord.bottomAnchor.constraint.equalTo(self.view.safeAreaLayoutGuide.bottomAnchor, constant: 66).isActive = true

I am getting an error ‘Reference to member ‘equalTo’ cannot be resolved without a contextual type’

May I know where I am going wrong and how to fix this issue? Thanks!

2

Answers


  1. translatesAutoresizingMaskIntoConstraints needs to be set as false.

    Code Be like:

    yourButton.translatesAutoresizingMaskIntoConstraints = false
    yourButton.bottomAnchor.constraint.equalTo(constraint: view.bottom, constant: 28)
    
    Login or Signup to reply.
  2. The syntax is wrong, Try This :

     btnAddRecord.translatesAutoresizingMaskIntoConstraints = false
     btnAddRecord.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -28).isActive = true
    

    Also view.bottomAnchor refer to superview and not safeArea , for setting it relative to safe area , you need to do like this :

     btn.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor, constant: -28).isActive = true
    

    28 negative will put it above the safe area.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search