Created
June 13, 2019 07:29
-
-
Save kambala-decapitator/28e7666434e680a6e324d600cb76caab to your computer and use it in GitHub Desktop.
objc code used to show screen properties of iOS device
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
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
__auto_type appLabel = [UILabel new]; | |
appLabel.translatesAutoresizingMaskIntoConstraints = NO; | |
appLabel.text = NSBundle.mainBundle.executablePath.lastPathComponent; | |
[self.view addSubview:appLabel]; | |
__auto_type createLabel = ^{ | |
__auto_type l = [UILabel new]; | |
l.numberOfLines = 0; | |
return l; | |
}; | |
__auto_type screen = UIScreen.mainScreen; | |
__auto_type scaleLabel = createLabel(); | |
scaleLabel.text = [NSString stringWithFormat:@"traits scale %.1lf\nscreen scale %.1lf\nscreen nativeScale %.1lf", self.traitCollection.displayScale, screen.scale, screen.nativeScale]; | |
__auto_type sizeLabel = createLabel(); | |
sizeLabel.text = [NSString stringWithFormat:@"fixed bounds %@\nnativeBounds %@", NSStringFromCGSize(screen.fixedCoordinateSpace.bounds.size), NSStringFromCGSize(screen.nativeBounds.size)]; | |
__auto_type verticalStack = [[UIStackView alloc] initWithArrangedSubviews:@[scaleLabel, sizeLabel]]; | |
verticalStack.axis = UILayoutConstraintAxisVertical; | |
verticalStack.spacing = 10; | |
verticalStack.translatesAutoresizingMaskIntoConstraints = NO; | |
[self.view addSubview:verticalStack]; | |
[NSLayoutConstraint activateConstraints:@[[appLabel.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor], | |
[appLabel.topAnchor constraintEqualToAnchor:self.topLayoutGuide.bottomAnchor], | |
[verticalStack.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor], | |
[verticalStack.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor]]]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment