Tag: swift3 nsmutableattributedstring

我怎样才能改变我的textView预先选定的单词的风格?

这是这个问题的后续如何在Swift中逐个更改我的UITextView中某些单词的样式? 感谢@ Josh的帮助,我能够写出一段代码,突出显示每个以#开头的单词,然后逐一完成。 我最后的代码是: func highlight (to index: Int) { let regex = try? NSRegularExpression(pattern: "#(\\w+)", options: []) let matches = regex!.matches(in: hashtagExplanationTextView.text, options: [], range: NSMakeRange(0, (hashtagExplanationTextView.text.characters.count))) let titleDict: NSDictionary = [NSForegroundColorAttributeName: orangeColor] let titleDict2: NSDictionary = [NSForegroundColorAttributeName: UIColor.red] let storedAttributedString = NSMutableAttributedString(string: hashtagExplanationTextView.text!, attributes: titleDict as! [String : AnyObject]) let attributedString = NSMutableAttributedString(attributedString: […]