@@ -21,13 +21,37 @@ public protocol SystemImage: RawRepresentable where RawValue == String {
21
21
///
22
22
/// Default implementation calls `loadImage` and nil-coalesces to `fallbackImage`.
23
23
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 }
24
35
25
36
/// Loads the named system image.
26
37
/// - Returns: The named system image or else `nil` if the system image cannot be loaded.
27
38
func loadImage( ) -> UIImage ?
28
39
}
29
40
30
41
extension 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
+
31
55
/// Fallback image to use in case a system image cannot be loaded.
32
56
/// (default is a 16 x 16 square filled with `.systemPink`)
33
57
public static var fallbackImage : UIImage {
@@ -44,7 +68,7 @@ extension SystemImage {
44
68
/// Default implementation uses `UIImage(systemName:)` passing in the associated `rawValue`.
45
69
/// - Returns: The named system image or else `nil` if the system image cannot be loaded.
46
70
public func loadImage( ) -> UIImage ? {
47
- UIImage ( systemName: rawValue)
71
+ UIImage ( systemName: rawValue, withConfiguration : Self . configuration )
48
72
}
49
73
50
74
/// A system image for this name value.
0 commit comments