Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kambala-decapitator/28e7666434e680a6e324d600cb76caab to your computer and use it in GitHub Desktop.
Save kambala-decapitator/28e7666434e680a6e324d600cb76caab to your computer and use it in GitHub Desktop.
objc code used to show screen properties of iOS device
- (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