我有這樣的代碼在我的手裏:如何使粗體成爲NSMutableString的一部分?
if let text = trimText?.mutableCopy() as? NSMutableString {
text.insertString("\(prefix) ", atIndex: 0)
textStorage.replaceCharactersInRange(range, withString: text as String)
}
當我試圖改變我的text
爲:
text = attributedTextFunc(text)
其中
func attributedTextFunc(str: NSString) -> NSAttributedString {
var attributedString = NSMutableAttributedString(string: str as String, attributes: [NSFontAttributeName:UIFont.systemFontOfSize(15.0)])
let boldFontAttribute = [NSFontAttributeName: UIFont.boldSystemFontOfSize(15.0)]
attributedString.addAttributes(boldFontAttribute, range: str.rangeOfString("More"))
return attributedString
}
,我得到這個錯誤:
Cannot assign value of type 'NSAttributedString' to type 'NSMutableString'
我怎樣才能使它大膽?
我使用這個庫https://github.com/ilyapuchka/ReadMoreTextView,我想改變修剪文本顏色和使其大膽。但是我不能=/ – Doe
是的,你應該在這個庫裏面做。 – Konstantin
@Doe你想要大膽'閱讀更多'文本? –