Created
July 11, 2014 17:56
-
-
Save tayhalla/70b8e2f1fae112eb44e3 to your computer and use it in GitHub Desktop.
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
/* | |
Creates a green btn and sets its position equal to a rect of {50.0f, 50.0f, 200.0f, 300.0f} | |
*/ | |
UIButton *btn = [[UIButton alloc] init]; | |
btn.backgroundColor = [UIColor greenColor]; | |
[btn setTranslatesAutoresizingMaskIntoConstraints:NO]; | |
[self.view addSubview:btn]; | |
NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:btn attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:0.0 constant:200]; | |
NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:btn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:0.0 constant:300]; | |
NSLayoutConstraint *vertConstraint = [NSLayoutConstraint constraintWithItem:btn attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:0.0 constant:50]; | |
NSLayoutConstraint *horizConstraint = [NSLayoutConstraint constraintWithItem:btn attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:0.0 constant:50]; | |
[self.view addConstraints:@[widthConstraint, heightConstraint, vertConstraint, horizConstraint]]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment