Access Auto Layout Constraint Programmatically

狂风中的少年 提交于 2019-12-04 12:59:19

Ok I figured it out. NSLayoutConstraint has a property named firstItem and a property secondItem. These are the views that the constraints are set on.

Usually the secondItem would be the view itself. Thus, view.constraints[0].secondItem is view.

Make an IBOutlet to the one you're interested in. You can make those from the constraint in the canvas (sometimes that's hard to do), or from the list of constraints in the scene list on the left.

The Other way and easy one for me is to Ctrl+Drag the Constraint's Outlet to ViewController.m or ViewController.h file and you can set/get it's constant, priority,first item, second item etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!