@@ -14,46 +14,29 @@ import UIKit
1414/// to `SystemImage`. The raw value of the enum should match a sytem image name (e.g. `checkmark.seal`).
1515public protocol SystemImage : RawRepresentable where RawValue == String {
1616 /// Fallback image to use in case a system image cannot be loaded.
17- /// (default is a 16 x 16 square filled with `.systemPink`)
1817 static var fallbackImage : UIImage { get }
1918
2019 /// A system image for this name value.
21- ///
22- /// Default implementation calls `loadImage` and nil-coalesces to `fallbackImage`.
2320 var image : UIImage { get }
2421
2522 /// Image will scale according to the specified text style.
2623 ///
27- /// Default implementation is `.body` .
24+ /// Return `nil` to not have the system image scale (not recommended) .
2825 static var textStyle : UIFont . TextStyle ? { get }
2926
30- /// Image configuration to be used in `loadImage()`.
31- ///
32- /// Default implementation is `UIImage.SymbolConfiguration(textStyle: textStyle)`.
33- /// Returns `nil` when `textStyle` is `nil`.
27+ /// Image configuration to be used to load the system image.
3428 static var configuration : UIImage . Configuration ? { get }
3529
30+ /// Rendering mode to use for the system image.
31+ static var renderingMode : UIImage . RenderingMode { get }
32+
3633 /// Loads the named system image.
3734 /// - Returns: The named system image or else `nil` if the system image cannot be loaded.
3835 func loadImage( ) -> UIImage ?
3936}
4037
4138extension 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-
55- /// Fallback image to use in case a system image cannot be loaded.
56- /// (default is a 16 x 16 square filled with `.systemPink`)
39+ /// Returns a 16 x 16 square filled with `.systemPink`.
5740 public static var fallbackImage : UIImage {
5841 let renderer = UIGraphicsImageRenderer ( size: CGSize ( width: 16 , height: 16 ) )
5942 let image = renderer. image { ctx in
@@ -63,17 +46,28 @@ extension SystemImage {
6346 return image
6447 }
6548
66- /// Loads the named system image.
67- ///
68- /// Default implementation uses `UIImage(systemName:)` passing in the associated `rawValue`.
69- /// - Returns: The named system image or else `nil` if the system image cannot be loaded.
49+ /// Returns `.body` text style.
50+ public static var textStyle : UIFont . TextStyle ? { . body }
51+
52+ /// Returns `UIImage.SymbolConfiguration(textStyle:)`
53+ /// passing in the specified `textStyle` or else returns `nil` if `textStyle` is `nil`.
54+ public static var configuration : UIImage . Configuration ? {
55+ guard let textStyle = textStyle else {
56+ return nil
57+ }
58+ return UIImage . SymbolConfiguration ( textStyle: textStyle)
59+ }
60+
61+ /// Returns `.automatic` rendering mode.
62+ public static var renderingMode : UIImage . RenderingMode { . automatic }
63+
64+ /// Returns `UIImage(systemName:)` passing in the associated `rawValue` and `configuration`
65+ /// and combined with the specified `renderingMode`.
7066 public func loadImage( ) -> UIImage ? {
71- UIImage ( systemName: rawValue, withConfiguration: Self . configuration)
67+ UIImage ( systemName: rawValue, withConfiguration: Self . configuration) ? . withRenderingMode ( Self . renderingMode )
7268 }
7369
74- /// A system image for this name value.
75- ///
76- /// Default implementation calls `loadImage` and nil-coalesces to `fallbackImage`.
70+ /// Returns `loadImage()` nil-coalesced to `fallbackImage`.
7771 public var image : UIImage {
7872 guard let image = loadImage ( ) else {
7973 if YCoreUI . isLoggingEnabled {
0 commit comments