Underline text in a UITextView

前端 未结 13 1399
情歌与酒
情歌与酒 2020-12-14 23:37

How can I underline text in a UITextView. I understand that I would need to create a subclass of UITextView, but what would go under drawRect

相关标签:
13条回答
  • 2020-12-14 23:59

    This is how I did it using Swift 5:

    let attributedString = NSMutableAttributedString(string: myTextView.text ?? "")
    myTextView.linkTextAttributes = [NSAttributedString.Key(rawValue: NSAttributedString.Key.underlineStyle.rawValue): NSUnderlineStyle.single.rawValue] as [NSAttributedString.Key: Any]?
    myTextView.attributedText = attributedString
    
    0 讨论(0)
提交回复
热议问题