Answer the question
In order to leave comments, you need to log in
How is it fashionable to make Constraints in code these days?
Actually, what is better to use now?
NSLayoutConstraint :
NSLayoutConstraint(item: stackView,
attribute: .leading,
relatedBy: .equal,
toItem: view,
attribute: .leadingMargin,
multiplier: 1,
constant: 0).isActive = true
let v = NSLayoutConstraint.constraints(
withVisualFormat: "V:|[topLayoutGuide]-[stackView]",
options: [],
metrics: nil,
views: views)
NSLayoutConstraint.activate(v)
myView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
myView.bottomAnchor.constraint(equalTo: view.topAnchor,
constant: 8).isActive=true
Answer the question
In order to leave comments, you need to log in
LayoutAnchor came with iOS 9, so if you have support with iOS 9, then use it, it's easy to write and more readable.
NSLayoutConstraint vs Visual Format Language
I preferred the first, the second was less clear to me, and it's easier to make a mistake there.
StackView is used, but without fanaticism, especially in table cells.
What's wrong with Traits? If you have support for multiple orientations, then use.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question