Skip to content

Instantly share code, notes, and snippets.

@paulofierro
Last active September 17, 2019 19:00
Show Gist options
  • Save paulofierro/c035b67e5257444306eabc06054086e1 to your computer and use it in GitHub Desktop.
Save paulofierro/c035b67e5257444306eabc06054086e1 to your computer and use it in GitHub Desktop.
A UIImage extension that returns a system image on iOS 13, otherwise returns an image from the Bundle provided.
extension UIImage {
/// Returns a system image on iOS 13, otherwise returns an image from the Bundle provided.
convenience init?(nameOrSystemName: String, in bundle: Bundle? = Bundle.main, compatibleWith traitCollection: UITraitCollection? = nil) {
if #available(iOS 13, *) {
self.init(systemName: nameOrSystemName, compatibleWith: traitCollection)
} else {
self.init(named: nameOrSystemName, in: bundle, compatibleWith: traitCollection)
}
}
}
// Sample usage:
// let image = UIImage(nameOrSystemName: "ellipses.bubble.fill")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment