繁体   English   中英

NSMutableAttributedString中的Swift替换字体大小

[英]Swift replacement font size in NSMutableAttributedString

我有一些属性:

var myAttributeMainText = [ NSFontAttributeName: UIFont(name: "Arial", size: 24.0)! ]
var myAttributeUpperText = [ NSBaselineOffsetAttributeName: 8, NSFontAttributeName: UIFont(name: "Arial", size: 14.0)! ]

我在文本标签中使用这些属性

var allMurableAttributedString = NSMutableAttributedString(string: "")
var userAttribute = NSMutableAttributedString(string: "USER", attributes: myAttributeMainText)
var newAttribute = NSMutableAttributedString(string: "NEW", attributes: myAttributeUpperText)
allMurableAttributedString.appendAttributedString(userAttribute)
allMurableAttributedString.appendAttributedString(newAttribute)

结果

然后,我将这些属性添加到CoreData allMurableAttributedString中,并具有以下内容:

USER{
    NSFont = "<UICTFont: 0x79feec20> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 0.00pt";
}

NEW{
    NSBaselineOffset = 6;
    NSFont = "<UICTFont: 0x79fed8e0> font-family: \"Thonburi\"; font-weight: normal; font-style: normal; font-size: 10.00pt";
}

调用属性时,如何更改属性allMurableAttributedString的字体大小?

从NSMutableAttributedString删除字体设置我用了这段代码

allMurableAttributedString.removeAttribute(NSFontAttributeName, range: NSMakeRange(0, 7))

然后我可以添加新的属性

allMurableAttributedString.setAttributes(myAttributeMainText, range: NSMakeRange(0, 4))
allMurableAttributedString.setAttributes(myAttributeUpperText, range: NSMakeRange(4, 3))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM