iOS 让Label根据其上的文字属性自适应显示

- (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];

}

你可能感兴趣的:(iOS 让Label根据其上的文字属性自适应显示)