How to add constraints programmatically using Swift

前端 未结 17 1512
逝去的感伤
逝去的感伤 2020-11-21 23:07

I\'m trying to figure this out since last week without going any step further. Ok, so I need to apply some constraints programmatically

17条回答
  •  感动是毒
    2020-11-21 23:44

    The error is caused by constrains automatically created from autoresizing mask, they are created because UIView property translatesAutoresizingMaskIntoConstraints is true by default.

    Consider using BoxView to get rid of all manual constraint creation boilerplate, and make your code concize and readable. To make layout in question with BoxView is very easy:

    boxView.items = [
       new_view.boxed.centerX().centerY().relativeWidth(1.0).relativeHeight(1.0)
    ]
    

提交回复
热议问题