Last active
December 27, 2015 18:49
-
-
Save robinhayward/7372570 to your computer and use it in GitHub Desktop.
NSLayoutContraint
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
NSArray *myConstraints = [NSLayoutConstraint RCH_constraintsWithCompleteVisualFormat:@"H:|-60-[self]| * V:|[self]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(self, self.superview)]; | |
+ (NSArray *)RCH_constraintsWithCompleteVisualFormat:(NSString *)format options:(NSLayoutFormatOptions)opts metrics:(NSDictionary *)metrics views:(NSDictionary *)views | |
{ | |
NSMutableArray *constraints = [NSMutableArray arrayWithCapacity:0]; | |
NSArray *markers = @[@"H:", @"V:"]; | |
NSArray *parts = [format componentsSeparatedByString:@"*"]; | |
for (NSString *formatStringPart in parts) { | |
for (NSString *markerString in markers) { | |
NSInteger marker = [formatStringPart rangeOfString:markerString].location; | |
if (marker != NSNotFound) { | |
NSString *trimmedFormatStringPart = [formatStringPart stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; | |
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:trimmedFormatStringPart options:opts metrics:metrics views:views]]; | |
} | |
} | |
} | |
return constraints; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment