Created
April 29, 2022 20:39
-
-
Save SoundBlaster/9f3b90290f40e3137cf12e41f530cc86 to your computer and use it in GitHub Desktop.
Simple multiline adjustable UILabel setup
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]; | |
UILabel *titleLabel = [UILabel new]; | |
titleLabel.font = [UIFont systemFontOfSize:17]; | |
titleLabel.numberOfLines = 3; | |
titleLabel.textAlignment = NSTextAlignmentCenter; | |
titleLabel.adjustsFontSizeToFitWidth = YES; | |
titleLabel.minimumScaleFactor = 0.5; | |
titleLabel.text = @"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo."; | |
titleLabel.backgroundColor = UIColor.redColor; | |
[self.view addSubview:titleLabel]; | |
self.titleLabel = titleLabel; | |
} | |
- (void)viewDidLayoutSubviews { | |
[super viewDidLayoutSubviews]; | |
CGSize titleLabelSize = [self.titleLabel sizeThatFits:CGSizeMake(200, CGFLOAT_MAX)]; | |
self.titleLabel.frame = (CGRect){ | |
.origin = CGPointMake(100, 400), | |
.size = titleLabelSize | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment