美文网首页Swift UI 交互 动效Swiftswift
使用swift给UILabel 添加不同字体大小和颜色的方法

使用swift给UILabel 添加不同字体大小和颜色的方法

作者: 羽翼de光辉 | 来源:发表于2015-08-17 22:06 被阅读5784次

var uname:String= "abcdefg hijklmn opq rst uvw xyz"

varmyMutableString =NSMutableAttributedString()

myMutableString =NSMutableAttributedString(string: uname, attributes: [NSFontAttributeName:UIFont(name:"Georgia", size:14.0)!])

添加不同字体颜色

myMutableString.addAttribute(NSForegroundColorAttributeName, value:FfontColor, range:NSRange(location:1,length:4))

//添加不同字体大小

myMutableString.addAttribute(NSFontAttributeName, value:UIFont.systemFontOfSize(12.0), range:NSRange(location:1,length:4))

Uname.attributedText= myMutableString

相关文章

网友评论

    本文标题:使用swift给UILabel 添加不同字体大小和颜色的方法

    本文链接:https://www.haomeiwen.com/subject/vrzwqttx.html