Skip to content

Instantly share code, notes, and snippets.

@onmyway133
Created November 23, 2014 03:54
Show Gist options
  • Save onmyway133/5817ca73b5b60b1e918b to your computer and use it in GitHub Desktop.
Save onmyway133/5817ca73b5b60b1e918b to your computer and use it in GitHub Desktop.
constraintForAttribute
- (NSLayoutConstraint *)constraintForAttribute:(NSLayoutAttribute)attribute
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"firstAttribute = %d && (firstItem = %@ || secondItem = %@)", attribute, self, self];
NSArray *constraintArray = [self.superview constraints];
if (attribute == NSLayoutAttributeWidth || attribute == NSLayoutAttributeHeight) {
constraintArray = [self constraints];
}
NSArray *fillteredArray = [constraintArray filteredArrayUsingPredicate:predicate];
if(fillteredArray.count == 0)
{
return nil;
}else
{
return fillteredArray.firstObject;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment