1 label的宽度自适应
CGFloat height = 30;
CGRect newRect = [self.labelOfMerName.text boundingRectWithSize:CGSizeMake(0, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil];
if (newRect.size.width > 220) {
newRect.size.width = 220;
}
self.labelOfMerName.frame = CGRectMake(50, 20, newRect.size.width, 30);
2 label的高度自适应
CGFloat width = 30;
CGRect newRect = [self.labelOfMerName.text boundingRectWithSize:CGSizeMake(width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil];
3 简单富文本(高亮)
NSRange range = [strOne rangeOfString:strTwo];
NSString *str = [NSString stringWithFormat:@"%@", strOne];
NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:str];
[attribute addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18] range:range];
[attribute addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range];
[textLabel setAttributedText:attribute];