以字符为单位换行,以字符为单位截断。
UILineBreakModeClip,
以单词为单位换行。以字符为单位截断。
UILineBreakModeHeadTruncation,
以单词为单位换行。如果是单行,则开始部分有省略号。如果是多行,则中间有省略号,省略号后面有4个字符。
UILineBreakModeTailTruncation,
以单词为单位换行。无论是单行还是多行,都是末尾有省略号。
UILineBreakModeMiddleTruncation,
以单词为单位换行。无论是单行还是多行,都是中间有省略号,省略号后面只有2个字符。
技巧:根据字符串长度自动适应宽度和高度
复制代码//这个frame是初设的,没关系,后面还会重新设置其size。
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)];
label.numberOfLines = 0;
label.backgroundColor = [UIColor clearColor];
NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:20],};
NSString *str = @"abcdefg你上课可是你的拿到了";
CGSize textSize = [str boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;;
[label setFrame:CGRectMake(100, 100, textSize.width, textSize.height)];
label.textColor = [UIColor greenColor];
label.text = str;
[self.view addSubview:label];
注:相关教程知识阅读请移步到IOS开发频道。










