以下代码,可以用来计算某个字符串在界面上显示时的高度,一般做界面自适应时会用到。 NSString* str = @"test testImplement viewDidLoad to do additional setup after loading the view, typically from a nib"; //可以精确计算字符串的换行,高宽等 CGSize labelSize = [str sizeWithFont:[UIFont boldSystemFontOfSize:17.0f] constrainedToSize:CGSizeMake(280, 100) //该字符串被放置的容器大小,主要是宽度 lineBreakMode:UILineBreakModeCharacterWrap];
转载于:https://www.cnblogs.com/liuxingzi/archive/2012/11/28/3404285.html