swift label不同颜色、不同字体

let string = "点击注册按钮,即表示您已同意隐私条款和服务协议"

        

        let ranStr = "同意"

        

        let attrstring:NSMutableAttributedString = NSMutableAttributedString(string:string)

        

        let str = NSString(string: string)

        

        let theRange = str.range(of: ranStr)

        

        attrstring.addAttribute(NSForegroundColorAttributeName, value: UIColor.red, range: theRange)

        

        attrstring.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 14), range: theRange)

        

        

        label.attributedText = attrstring

posted @   zuidap  阅读(5895)  评论(0编辑  收藏  举报
编辑推荐:
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
· ASP.NET Core 模型验证消息的本地化新姿势
· 对象命名为何需要避免'-er'和'-or'后缀
阅读排行:
· “你见过凌晨四点的洛杉矶吗?”--《我们为什么要睡觉》
· 编程神器Trae:当我用上后,才知道自己的创造力被低估了多少
· C# 从零开始使用Layui.Wpf库开发WPF客户端
· C#/.NET/.NET Core技术前沿周刊 | 第 31 期(2025年3.17-3.23)
· 开发的设计和重构,为开发效率服务
点击右上角即可分享
微信分享提示