因为NSString里已经有相应的方法提供给你来进行计算了,所以实现起来只要简单的几句。
这里是关键:
NSString * desc = @"Description it is a test font, and don't become angry for which i use to do here.Now here is a very nice party from american or not!";
CGSize size = [desc sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(240, 2000) lineBreakMode:UILineBreakModeWordWrap];
然后进行相应的设置:
[lblLabel setNumberOfLines:0];
[lblLabel setFrame:CGRectMake(40, 135, 240, size.height+10)];
[lblLabel setText:desc];
注意这里uilabel的numberoflines(即最大行数限制)设置成0,即不做行数限制。
textview的类似,就不在说明了。