I am trying to programmatically set my constraints to the top of my UIViewController's Nav Bar, but I can't see to get it to work properly. Here is my code:
func setup() {
let containerView = UIView()
containerView.backgroundColor = .red
containerView.translatesAutoresizingMaskIntoConstraints = false
let payeeNameTextField = UITextField()
payeeNameTextField.backgroundColor = .green
payeeNameTextField.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(containerView)
view.addSubview(payeeNameTextField)
//iOS 9 Constraints
//x,y,w,h
// Constraint To Nav Bar
containerView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
containerView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
containerView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
containerView.heightAnchor.constraint(equalToConstant: 20).isActive = true
// Constraint to Bottom Anchor
payeeNameTextField.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
payeeNameTextField.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
payeeNameTextField.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
payeeNameTextField.heightAnchor.constraint(equalToConstant: 50).isActive = true
}
I know setting it topAnchor is wrong, but I have tried to mess around with this and just cant seem to get the red background to show up.
Thanks in advance for any input!!