2017-12-11 9 views
0

NSAttributedStringUITextViewに設定されていますので、NSAttributedStringKey.foregroundColorの値を確認する必要があります。NSAttributed文字列の前景色を確認してください

char = attributedText.attributedSubstring(from: attributedRange) 

このフィルタを使用しようとしましたが、実際にはどのように使用するのかわかりません。

let attr = char.attributes(at: 0, effectiveRange: nil) 
attr.filter({ (<#(key: NSAttributedStringKey, value: Any)#>) -> Bool in 
      //if true... 
     }) 

答えて

2

代わりにattributesattribute方法を使用することが容易になるだろう:

char = attributedText.attributedSubstring(from: attributedRange) 
if let color = char.attribute(.foregroundColor, at: 0, effectiveRange: nil) as? UIColor { 
    // color is the foreground color at location 0 
} else { 
    // there is no foreground color at location 0 
} 
+0

本当だ...おかげで:)))) –

関連する問題