Kikidesign

一枚码农

iOS8下UILabel如何自适应高度(自动换行)

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 100, 300, 100)];

label.numberOfLines = 0;

label.lineBreakMode = NSLineBreakByWordWrapping;

label.text = @“我又专心察明智慧、狂妄和愚昧,乃知这也是捕风.因为多有智慧,就多有愁烦;加增知识的,就加增忧伤.And I applied my mind to know wisdom and to know madness and folly.I perceived that this also is but a chasing after wind.For in much wisdom is much vexation,and those who increase knowledge increase sorrow.”;

CGSize size = [label sizeThatFits:CGSizeMake(label.frame.size.width, MAXFLOAT)];

label.frame =CGRectMake(10, 100, 300, size.height);

label.font = [UIFont systemFontOfSize:14];

[self.view addSubview:label];

评论