Last active
August 29, 2015 13:58
-
-
Save altyus/10299517 to your computer and use it in GitHub Desktop.
Center two labels in view with Visual Format Language
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
self.stepLabel = [[UILabel alloc] init]; | |
self.stepLabel.text = @"0 Steps"; | |
self.stepLabel.textAlignment = NSTextAlignmentCenter; | |
self.stepLabel.font = [UIFont fontWithName:@"HelveticaNeue-UltraLight" size:50]; | |
self.historicalLabel = [[UILabel alloc] init]; | |
self.historicalLabel.text = @"Historical"; | |
self.historicalLabel.textAlignment = NSTextAlignmentCenter; | |
self.historicalLabel.font = [UIFont fontWithName:@"HelveticaNeue-UltraLight" size:50]; | |
[self.view setTranslatesAutoresizingMaskIntoConstraints:NO]; | |
[self.stepLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; | |
[self.historicalLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; | |
[self.view addSubview:self.stepLabel]; | |
[self.view addSubview:self.historicalLabel]; | |
NSDictionary *views = @{@"superview" : self.view, | |
@"stepLabel" : self.stepLabel, | |
@"historicalLabel" : self.historicalLabel}; | |
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[superview]-(<=1)-[stepLabel]" options:NSLayoutFormatAlignAllCenterY metrics:nil views:views]]; | |
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[superview]-(<=1)-[stepLabel]-(20)-[historicalLabel]" options:NSLayoutFormatAlignAllCenterX metrics:nil views:views]]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment