search

Home  >  Q&A  >  body text

ios - addAttribute不起作用

我想用这段代码将我选中的textview中的内容更改一个字体,但是没有起作用。大神们知道为什么么?

let string = NSMutableAttributedString(string: bodyView.inputBodyTV.text)
string.addAttribute(NSFontAttributeName, value: UIFont.boldSystemFontOfSize(15), range: selecteRange)
PHPzPHPz2898 days ago656

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:43:05

    1. Check if selecteRange is correct

    2. Use textView.attributedText, not textView.text

    3. After modification, you need to reassign textview

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:43:05

    +1 from upstairs, use textView.attributedText, not textView.text

    reply
    0
  • Cancelreply