iOS 让Label根据其上的文字属性自适应显示
2016-08-30 本文已影响269人
LD_左岸
- (void)viewDidLoad {
[super viewDidLoad];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 100, 300, 100)];
label.text = @"fewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdf";
label.numberOfLines = 0;
label.lineBreakMode = NSLineBreakByWordWrapping;
CGSize size = [label sizeThatFits:CGSizeMake(label.frame.size.width, MAXFLOAT)];
label.frame =CGRectMake(10, 100, 300, size.height);
label.backgroundColor = [UIColor redColor];
[self.view addSubview:label];
}