Created
October 23, 2013 13:36
-
-
Save rcdilorenzo/7118912 to your computer and use it in GitHub Desktop.
A piece of code for doing auto layout in a UIView subclass
This file contains 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
// Declare this property in your header / private header | |
@property (nonatomic, strong) NSMutableArray *updatingConstraints; | |
- (void)updateConstraints { | |
if (self.updatingConstraints) { | |
[self removeConstraints:self.updatingConstraints]; | |
} | |
self.updatingConstraints = [NSMutableArray array]; | |
// Create and add all of your constraints here | |
[super updateConstraints]; | |
} | |
- (void)addConstraint:(NSLayoutConstraint *)constraint { | |
[super addConstraint:constraint]; | |
[self.updatingConstraints addObject:constraint]; | |
} | |
- (void)addConstraints:(NSArray *)constraints { | |
[super addConstraints:constraints]; | |
[self.updatingConstraints addObjectsFromArray:constraints]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment