D
D
doublench212017-10-11 12:55:17
iOS
doublench21, 2017-10-11 12:55:17

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

Visual Format Language :
let v = NSLayoutConstraint.constraints(
  withVisualFormat: "V:|[topLayoutGuide]-[stackView]",
  options: [],
  metrics: nil,
  views: views)
NSLayoutConstraint.activate(v)

Layout Anchors :
myView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
myView.bottomAnchor.constraint(equalTo: view.topAnchor,
       constant: 8).isActive=true

Do they use StackViews? And what about Traits in the code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Tikhonov, 2017-10-11
@doublench21

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 question

Ask a Question

731 491 924 answers to any question