私は私の手でこのコードを持っている:太字を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'
どうすれば太字にすることができますか?
に、この関数の戻り値を代入し、それを太字にする。しかし、私は=/ – Doe
できません。はい、あなたはこのライブラリの中で行うべきです。 – Konstantin
@Doe大胆な 'Read More'テキストを作りたいですか? –