Last active
August 29, 2015 13:58
-
-
Save samsonjs/10344353 to your computer and use it in GitHub Desktop.
Auto layout sadness, what am I doing wrong?
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
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
UITextView *hi = [[UITextView alloc] init]; | |
hi.translatesAutoresizingMaskIntoConstraints = NO; | |
hi.text = @"hi there"; | |
hi.textColor = [UIColor blackColor]; | |
[hi sizeToFit]; | |
[self.view addSubview:hi]; | |
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:hi | |
attribute:NSLayoutAttributeCenterX | |
relatedBy:NSLayoutRelationEqual | |
toItem:self.view | |
attribute:NSLayoutAttributeCenterX | |
multiplier:1.0 | |
constant:0.0]]; | |
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:hi | |
attribute:NSLayoutAttributeCenterY | |
relatedBy:NSLayoutRelationEqual | |
toItem:self.view | |
attribute:NSLayoutAttributeCenterY | |
multiplier:1.0 | |
constant:0.0]]; | |
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:hi | |
attribute:NSLayoutAttributeWidth | |
relatedBy:NSLayoutRelationEqual | |
toItem:self.view | |
attribute:NSLayoutAttributeWidth | |
multiplier:1.0 | |
constant:0.0]]; | |
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:hi | |
attribute:NSLayoutAttributeHeight | |
relatedBy:NSLayoutRelationEqual | |
toItem:self.view | |
attribute:NSLayoutAttributeHeight | |
multiplier:1.0 | |
constant:0.0]]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment