It seems like it should be a simple task, but is there a way to say programmatically if it NSLayoutConstraintis a horizontal or vertical constraint?
The only way I can try to do this is to call [constraint description];and then search in the resulting string for "V:"or"H:"
I want to find this information: I have two almost identical restrictions set on prototype UITableViewCellmy own storyboard, the only difference is that we describe the horizontal distance from superviewand the other vertical. I want to remove vertical, programmatically add constraints to describe adding a new view, given that a specific parameter is being returned from my server.
Any suggestions would be extremely helpful!
EDIT:
I accepted greymouser's answer because its explanation is a fantastic answer, and I did work on parsing the description, but I also want to give credit to @kongtomorrow, who also suggested this answer via twitter before greymouser answered me here! Thanks for the help!
Here is the actual code that I used to find the constraint:
NSArray *constraints = [bubble constraints];
for (NSLayoutConstraint *constraint in constraints) {
if ([[constraint firstItem] isEqual:messageLabel] && [[constraint secondItem] isEqual:bubble] && [constraint secondAttribute] == NSLayoutAttributeTop) {
[bubble removeConstraint:constraint];
}
}
firstItem, secondItem, secondAttribute , , , !