示例:
let dummy = UILabel()
dummy.text = "this is a String"
我希望视图能够显示这样的内容。此外,是否可以更改" String"的字体大小。在虚拟?
这是字符串
答案 0 :(得分:0)
您可以使用NSAttributedString执行此操作:
let dummy = UILabel()
let theString = "this is a String"
let attributedString = NSMutableAttributedString(string: theString, attributes: [NSFontAttributeName:UIFont.systemFontOfSize(12.0)])
let boldFontAttribute = [NSFontAttributeName: UIFont.boldSystemFontOfSize(24.0)]
attributedString.addAttributes(boldFontAttribute, range: NSMakeRange(10, theString.characters.count))
dummy.attributedText = attributedString