Created
November 23, 2014 03:54
-
-
Save onmyway133/5817ca73b5b60b1e918b to your computer and use it in GitHub Desktop.
constraintForAttribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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