Created
August 13, 2021 16:41
-
-
Save robertmryan/a3acce637929bb75efa40c934681363b to your computer and use it in GitHub Desktop.
This file contains 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
struct Images { | |
static func minus(pointSize: CGFloat? = nil) -> UIImage? { | |
image(named: "minus", pointSize: pointSize) | |
} | |
static func trash(pointSize: CGFloat? = nil) -> UIImage? { | |
image(named: "trash", pointSize: pointSize) | |
} | |
private static func image(named name: String, pointSize: CGFloat? = nil) -> UIImage? { | |
let configuration = UIImage.SymbolConfiguration(pointSize: pointSize ?? 24) // use whatever default size you want | |
return UIImage(systemName: name, withConfiguration: configuration) | |
} | |
} |
Another option (one that honors accessibility settings) is to use UIFont.TextStyle
:
struct Images {
static func minus(textStyle: UIFont.TextStyle? = nil) -> UIImage? {
image(named: "minus", textStyle: textStyle)
}
static func trash(textStyle: UIFont.TextStyle? = nil) -> UIImage? {
image(named: "trash", textStyle: textStyle)
}
private static func image(named name: String, textStyle: UIFont.TextStyle? = nil) -> UIImage? {
let configuration = UIImage.SymbolConfiguration(textStyle: textStyle ?? .body)
return UIImage(systemName: name, withConfiguration: configuration)
}
}
And then you can do things like:
imageView.image = Images.minus(textStyle: .headline)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then you can do things like:
Or