@@ -21,13 +21,37 @@ public protocol SystemImage: RawRepresentable where RawValue == String {
2121 ///
2222 /// Default implementation calls `loadImage` and nil-coalesces to `fallbackImage`.
2323 var image : UIImage { get }
24+
25+ /// Image will scale according to the specified text style.
26+ ///
27+ /// Default implementation is `.body`.
28+ static var textStyle : UIFont . TextStyle ? { get }
29+
30+ /// Image configuration to be used in `loadImage()`.
31+ ///
32+ /// Default implementation is `UIImage.SymbolConfiguration(textStyle: textStyle)`.
33+ /// Returns `nil` when `textStyle` is `nil`.
34+ static var configuration : UIImage . Configuration ? { get }
2435
2536 /// Loads the named system image.
2637 /// - Returns: The named system image or else `nil` if the system image cannot be loaded.
2738 func loadImage( ) -> UIImage ?
2839}
2940
3041extension SystemImage {
42+ /// Image will scale according to the specified text style.
43+ public static var textStyle : UIFont . TextStyle ? { . body }
44+
45+ /// Image configuration to be used in `loadImage()`.
46+ ///
47+ /// Returns `nil` when `textStyle` is `nil`.
48+ public static var configuration : UIImage . Configuration ? {
49+ guard let textStyle = textStyle else {
50+ return nil
51+ }
52+ return UIImage . SymbolConfiguration ( textStyle: textStyle)
53+ }
54+
3155 /// Fallback image to use in case a system image cannot be loaded.
3256 /// (default is a 16 x 16 square filled with `.systemPink`)
3357 public static var fallbackImage : UIImage {
@@ -44,7 +68,7 @@ extension SystemImage {
4468 /// Default implementation uses `UIImage(systemName:)` passing in the associated `rawValue`.
4569 /// - Returns: The named system image or else `nil` if the system image cannot be loaded.
4670 public func loadImage( ) -> UIImage ? {
47- UIImage ( systemName: rawValue)
71+ UIImage ( systemName: rawValue, withConfiguration : Self . configuration )
4872 }
4973
5074 /// A system image for this name value.
0 commit comments