2

の中に奇妙なものが見えますUITextView。はUITextView住所を検出できますが、電話番号と Web リンクのスタイルを設定できますが、テキストのスタイルを設定できません。

以下のコードを参照してください(私はtintColor&を試しましたlinkTextAttributes-両方ともアドレスリンク以外のものに適用されるようです)

let t = "One Infinite Loop Cupertino, CA 95014 some other text yeah www.google.com 123-555-1212 One Infinite Loop Cupertino, CA 95014"
let a = NSAttributedString(string: t)

self.textView.attributedText = a
self.textView.isEditable = false

self.textView.textColor = .green
self.textView.tintColor = .blue

self.textView.dataDetectorTypes = [.link, .address, .phoneNumber]

let linkAttributes: [String : Any] = [
    NSAttributedStringKey.foregroundColor.rawValue: UIColor.red,
    NSAttributedStringKey.underlineColor.rawValue: UIColor.orange,
    NSAttributedStringKey.underlineStyle.rawValue: NSUnderlineStyle.styleSingle.rawValue]

self.textView.linkTextAttributes = linkAttributes

ここに画像の説明を入力

ご覧のとおり、アドレスは下線付きでクリック可能 (クリックするとマップに移動します) ですが、データ検出器によって検出された他のものが検出されて、赤色は適用されません。

考え?

4

0 に答える 0