Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

User memory-based instances of UIImage in StyleXML #101

Closed
malcommac opened this issue Jan 12, 2020 · 1 comment
Closed

User memory-based instances of UIImage in StyleXML #101

malcommac opened this issue Jan 12, 2020 · 1 comment
Assignees
Milestone

Comments

@malcommac
Copy link
Owner

It would be good to use passed in-memory instances of UIImage objects used when parsing StyleGroup/StyleXML images. If mapping is not resolved the default fallback should be the any compiled .xcassets file.

@malcommac malcommac self-assigned this Jan 12, 2020
@malcommac malcommac added this to the 3.6.0 milestone Jan 12, 2020
@malcommac
Copy link
Owner Author

malcommac commented Jan 12, 2020

The XMLDynamicAttributesResolver class now provides an additional method called:

func imageWithName(_ name: String, fromStyle style: StyleXML) -> UIImage?

The default implementation of this method:

  • check if caller StyleXML instance return any non-nil image instances in imageProvider callback.
  • if nil search inside any bundled xcasset file for this image (aka UIImage(named:)).
  • If 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)

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant