Keg*_* K. 1 uitextview nsattributedstring ios swift
我有一套NSAttributedString
,UITextView
我需要检查它的NSAttributedStringKey.foregroundColor
价值。
char = attributedText.attributedSubstring(from: attributedRange)
Run Code Online (Sandbox Code Playgroud)
我尝试使用这个过滤器,但我真的不知道如何使用它。
let attr = char.attributes(at: 0, effectiveRange: nil)
attr.filter({ (<#(key: NSAttributedStringKey, value: Any)#>) -> Bool in
//if true...
})
Run Code Online (Sandbox Code Playgroud)
使用该attribute
方法会更容易,而不是attributes
:
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
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
455 次 |
最近记录: |