Skip to content

Responsive auto layout

André J edited this page Apr 26, 2021 · 2 revisions

This code makes the parent unable to resize bellow 400px

$0.activateConstraints { view in
   let anchor = Constraint.anchor(view, to: self, align: .centerCenter, alignTo: .centerCenter)
   let minorWidth = Constraint.width(view, width: 400, multiplier: 1, relation: .equal)
   minorWidth.priority = NSLayoutConstraint.Priority(rawValue: 999)
   // changing the bellow relation to: greaterThanOrEqual forces the parent to never resize above 400px
   let majorWidth = Constraint.width(view, to: self, offset: -44, multiplier: 1, relation: .lessThanOrEqual)
   majorWidth.priority = NSLayoutConstraint.Priority(rawValue: 1000)
   let h = Constraint.height(view, height: 400)
   /*let w = Constraint.width(view, width: 400)*/
   return [anchor.x, anchor.y, minorWidth, majorWidth, h]
}
Clone this wiki locally