UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 200, Width, 100)];
lable.numberOfLines=0;
[self.view addSubview:lable];
NSAttributedString *subStr1 = [[NSAttributedString alloc] initWithString:@"好傻好傻好傻好撒婚纱和撒谎莎婚纱和傻好傻好撒婚纱和撒谎莎婚纱和傻好傻好撒婚纱和撒谎莎婚纱和傻好傻好撒婚纱和撒谎莎婚纱和撒谎莎莎婚纱"
attributes:@{NSForegroundColorAttributeName:[UIColor redColor],
NSFontAttributeName:[UIFont systemFontOfSize:15]
}];
NSAttributedString *subStr2 = [[NSAttributedString alloc] initWithString:@"哈哈哈哈哈哈哈"
attributes:@{NSForegroundColorAttributeName:[UIColor blueColor],
NSFontAttributeName:[UIFont systemFontOfSize:15]
}];
NSTextAttachment *attch = [[NSTextAttachment alloc] init];
attch.image=[UIImage imageNamed:@"error"];
attch.bounds=CGRectMake(0, -3, [UIFont systemFontOfSize:15].lineHeight, [UIFont systemFontOfSize:15].lineHeight);
NSAttributedString *subStr3 = [NSAttributedString attributedStringWithAttachment:attch];
NSMutableAttributedString *attrText = [[NSMutableAttributedString alloc] init];
[attrText appendAttributedString:subStr1];
[attrText appendAttributedString:subStr2];
[attrText appendAttributedString:subStr3];
lable.attributedText=attrText;
UILable换行底部增加图片
最新推荐文章于 2021-01-22 18:06:30 发布