小编Ada*_*ant的帖子

UITextView - 无法在文本上设置下划线或删除线属性?

每当我尝试在UITextView的attributedText上设置下划线或删除线属性时,我都会遇到运行时故障.其他属性,如字体和背景颜色没有问题.这是一段代码片段.我所拥有的只是一个带有单个UITextView的测试项目.我在iOS 11上.

class ViewController: UIViewController {

    @IBOutlet weak var myTextView: UITextView!

    var myMutableString = NSMutableAttributedString(string: "")

    override func viewDidLoad() {
        super.viewDidLoad()

        let string = "The cow jumped over the moon" as NSString
        myMutableString = NSMutableAttributedString(string: string as String)

        let underlineAttribute = [NSAttributedStringKey.underlineStyle: NSUnderlineStyle.styleSingle]

        myMutableString.addAttributes(underlineAttribute, range: string.range(of: "cow"))

        myTextView.attributedText = myMutableString
    }
}
Run Code Online (Sandbox Code Playgroud)

这导致文本消失并打印出一些错误:

2017-11-05 19:43:34.708830-0800 UITextView_Test[11771:907014]
-[_SwiftValue _getValue:forType:]: unrecognized selector sent to instance 0x60c00004eb50 2017-11-05 19:43:34.709351-0800 UITextView_Test[11771:907014] <NSATSTypesetter: 0x60800016be80>: Exception -[_SwiftValue _getValue:forType:]: unrecognized selector sent to instance 0x60c00004eb50 raised during …
Run Code Online (Sandbox Code Playgroud)

uitextview uikit appkit ios textkit

13
推荐指数
1
解决办法
2240
查看次数

标签 统计

appkit ×1

ios ×1

textkit ×1

uikit ×1

uitextview ×1