Skip to content

Instantly share code, notes, and snippets.

@rcdilorenzo
Created October 23, 2013 13:36
Show Gist options
  • Save rcdilorenzo/7118912 to your computer and use it in GitHub Desktop.
Save rcdilorenzo/7118912 to your computer and use it in GitHub Desktop.
A piece of code for doing auto layout in a UIView subclass
// 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