Created
August 15, 2012 02:56
-
-
Save justin/3355259 to your computer and use it in GitHub Desktop.
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
NSView *contentView = [self.window contentView]; | |
self.button = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 200, 50.0f)]; | |
[self.button setTranslatesAutoresizingMaskIntoConstraints:NO]; | |
[self.button setTitle:@"This is a test button"]; | |
[self.button setBordered:YES]; | |
[contentView addSubview:self.button]; | |
NSButton *button = self.button; | |
NSDictionary *views = NSDictionaryOfVariableBindings(contentView, button); | |
[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[button(>=50)]" options:NSLayoutFormatAlignAllTop metrics:nil views:views]]; | |
[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[button(>=50)]-|" options:NSLayoutFormatAlignAllBaseline metrics:nil views:views]]; | |
[contentView addConstraints:@[ | |
[NSLayoutConstraint constraintWithItem:self.button | |
attribute:NSLayoutAttributeCenterY | |
relatedBy:NSLayoutRelationEqual | |
toItem:contentView | |
attribute:NSLayoutAttributeCenterY | |
multiplier:1.0 | |
constant:0]]]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment