ios中label富文本的设置

更新时间:2023-05-09 06:14:07 阅读: 评论:0

ios中label富⽂本的设置1.修改不同⽂字和颜⾊
// 创建⼀个富⽂本
NSMutableAttributedString *attri =    [[NSMutableAttributedString alloc] initWithString:@"哈哈哈哈哈123456789"];    // 修改富⽂本中的不同⽂字的样式
[attri addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0, 5)];
[attri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 5)];
// 设置数字为红⾊
[attri addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(5, 9)];
[attri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(5, 9)];
2,添加图⽚
// 添加表情
NSTextAttachment *attch = [[NSTextAttachment alloc] init];
// 表情图⽚
attch.image = [UIImage imageNamed:@"d_aini"];
// 设置图⽚⼤⼩
attch.bounds = CGRectMake(0, 0, 32, 32);
// 创建带有图⽚的富⽂本
NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
[attri appendAttributedString:string];
//
attri是上⾯定义的对象
// ⽤label的attributedText属性来使⽤富⽂本 lf.textLabel.attributedText = attri;

本文发布于:2023-05-09 06:14:07,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/873138.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:设置   创建   表情
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图