Skip to content

Instantly share code, notes, and snippets.

@SoundBlaster
Created April 29, 2022 20:39
Show Gist options
  • Save SoundBlaster/9f3b90290f40e3137cf12e41f530cc86 to your computer and use it in GitHub Desktop.
Save SoundBlaster/9f3b90290f40e3137cf12e41f530cc86 to your computer and use it in GitHub Desktop.
Simple multiline adjustable UILabel setup
- (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