Advertisement
Don_Mag

constraint syntax

Dec 1st, 2021
1,029
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.95 KB | None | 0 0
  1.  
  2. // standard constraint syntax
  3.  
  4.             NSLayoutConstraint.activate([
  5.                 avatar.widthAnchor.constraint(equalToConstant: 40.0),
  6.                 avatar.heightAnchor.constraint(equalToConstant: 40.0),
  7.  
  8.                 stack.topAnchor.constraint(equalTo: titleView.topAnchor),
  9.                 stack.leadingAnchor.constraint(equalTo: titleView.leadingAnchor),
  10.                 stack.trailingAnchor.constraint(lessThanOrEqualTo: titleView.trailingAnchor),
  11.                 stack.bottomAnchor.constraint(equalTo: titleView.bottomAnchor),
  12.             ])
  13.  
  14.             let c = titleView.widthAnchor.constraint(equalToConstant: CGFloat.greatestFiniteMagnitude)
  15.             c.priority = .defaultLow
  16.             c.isActive = true
  17.  
  18. // or, if you want to use SnapKit
  19.  
  20.             avatar.snp.makeConstraints { make in
  21.                 make.width.height.equalTo(40)
  22.             }
  23.             stack.snp.makeConstraints { make in
  24.                 make.top.leading.trailing.bottom.equalToSuperview()
  25.             }
  26.             titleView.snp.makeConstraints { make in
  27.                 make.width.equalTo(CGFloat.greatestFiniteMagnitude).priority(.low)
  28.             }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement