Closed malcommac closed 4 years ago
The XMLDynamicAttributesResolver
class now provides an additional method called:
func imageWithName(_ name: String, fromStyle style: StyleXML) -> UIImage?
The default implementation of this method:
StyleXML
instance return any non-nil image instances in imageProvider
callback.nil
search inside any bundled xcasset
file for this image (aka UIImage(named:)
).nil
the entire tag is ignored.This is an example:
let text = """
- <img named="check"/> Performed!
"""
let base = Style {
$0.font = UIFont.boldSystemFont(ofSize: 14)
$0.color = UIColor(hexString: "#8E8E8E")
}
let xmlStyle = StyleXML(base: base)
xmlStyle.imageProvider = { imageName in
switch imageName {
case "check":
return UIColor.red.image(CGSize(width: 30, height: 30))
default:
// ...
}
}
self.textView?.attributedText = text.set(style: x)
It would be good to use passed in-memory instances of
UIImage
objects used when parsingStyleGroup
/StyleXML
images. If mapping is not resolved the default fallback should be the any compiled.xcassets
file.