Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Auto-Layout Constraints for Specific Object

I have a UIImageView embedded in a UIView. My entire app uses AutoLayout, but I want to remove constraints for the UIImageView. Xcode will not allow me to delete the constraints, is there a way to disable them for a specific object, set them to zero, something?

like image 239
Eric Avatar asked Nov 14 '12 21:11

Eric


People also ask

How do I remove a constraint from a storyboard?

To remove a single constraint just select it and hit delete. To remove constraints for a single view you select the view and hit the triangle button in the bottom right hand corner... And hit "Clear Constraints" under the "Selected Views" part.

How do I delete a constraint in Swift?

Just select the view you want to remove a constraint from and open the size inspector. You should see a list of all the constraints. Select the one you want to delete, and press the delete key.

What are two properties that auto layout constraints control on a UIView?

Auto Layout defines margins for each view. These margins describe the preferred spacing between the edge of the view and its subviews. You can access the view's margins using either the layoutMargins or layoutMarginsGuide property. The layoutMargins property lets you get and set the margins as a UIEdgeInsets structure.


2 Answers

I agree Xcode auto-layout is horrible to use if you want something particular...

What I use to remove constraints programatically:

[detailsPhotoView removeConstraints:detailsPhotoView.constraints]; 
like image 121
Thomas Decaux Avatar answered Oct 13 '22 04:10

Thomas Decaux


In XCode 5 there is an option while editing constraints 'Remove at build time'. If this is enabled the constraint will automatically be removed during run-time. The option is there to keep Interface Builder happy if you don't want particular constraints.

like image 29
Christian Avatar answered Oct 13 '22 04:10

Christian