Reputation: 132
I am making constraints with the visual language, but whenever I try to add them it causes an error.
class TimerViewController : UIViewController{
let timer = TimerView()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .white
self.view.addSubview(timer)
self.createContraints()
}
func createContraints(){
self.timer.translatesAutoresizingMaskIntoConstraints = false
let horizontalConstraints =
NSLayoutConstraint.constraints(withVisualFormat: "H:|[timer]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["timer" : timer])
let verticleContraints =
NSLayoutConstraint.constraints(withVisualFormat: "V:|==[timer]==|", options: NSLayoutFormatOptions(), metrics: nil, views: ["timer" : timer])
self.view.addConstraints(horizontalConstraints)
self.view.addConstraints(verticleContraints)
}
}
Upvotes: 0
Views: 146
Reputation: 23485
Xcode gives you the error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse constraint format:
Expected a view
V:|==[timer]==|
^'
So remove the == and it will work.
Upvotes: 2