Last active
September 17, 2019 19:00
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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