Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudkite committed Dec 1, 2015
1 parent 49fe2b9 commit 1074194
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,50 @@ Will attempt to recover by breaking constraint

For an example of how to set this up take a look at the **Masonry iOS Examples** project in the Masonry workspace.

## Where should I create my constraints?

```objc
@implementation DIYCustomView

- (id)init {
self = [super init];
if (!self) return nil;

// --- Create your views here ---
self.button = [UIButton new];

return self;
}

// tell UIKit that you are using AutoLayout
+ (BOOL)requiresConstraintBasedLayout {
return YES;
}

// this is Apple's recommended place for adding/updating constraints
- (void)updateConstraints {

// --- remake/update constraints here
[self.button remakeConstraints:^(MASConstraintMaker *make) {
make.width.equalTo(@(self.buttonSize.width));
make.height.equalTo(@(self.buttonSize.height));
}];

//according to apple super should be called at end of method
[super updateConstraints];
}

- (void)didTapButton:(UIButton *)button {
// --- Do your changes ie change variables that affect your layout etc ---
self.buttonSize = CGSize(200, 200);

// tell constraints they need updating
[self setNeedsUpdateConstraints];
}

@end
```
## Installation
Use the [orsome](http://www.youtube.com/watch?v=YaIZF8uUTtk) [CocoaPods](http://github.com/CocoaPods/CocoaPods).
Expand Down

0 comments on commit 1074194

Please sign in to comment.