@@ -14,46 +14,29 @@ import UIKit
14
14
/// to `SystemImage`. The raw value of the enum should match a sytem image name (e.g. `checkmark.seal`).
15
15
public protocol SystemImage : RawRepresentable where RawValue == String {
16
16
/// Fallback image to use in case a system image cannot be loaded.
17
- /// (default is a 16 x 16 square filled with `.systemPink`)
18
17
static var fallbackImage : UIImage { get }
19
18
20
19
/// A system image for this name value.
21
- ///
22
- /// Default implementation calls `loadImage` and nil-coalesces to `fallbackImage`.
23
20
var image : UIImage { get }
24
21
25
22
/// Image will scale according to the specified text style.
26
23
///
27
- /// Default implementation is `.body` .
24
+ /// Return `nil` to not have the system image scale (not recommended) .
28
25
static var textStyle : UIFont . TextStyle ? { get }
29
26
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.
34
28
static var configuration : UIImage . Configuration ? { get }
35
29
30
+ /// Rendering mode to use for the system image.
31
+ static var renderingMode : UIImage . RenderingMode { get }
32
+
36
33
/// Loads the named system image.
37
34
/// - Returns: The named system image or else `nil` if the system image cannot be loaded.
38
35
func loadImage( ) -> UIImage ?
39
36
}
40
37
41
38
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
-
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`.
57
40
public static var fallbackImage : UIImage {
58
41
let renderer = UIGraphicsImageRenderer ( size: CGSize ( width: 16 , height: 16 ) )
59
42
let image = renderer. image { ctx in
@@ -63,17 +46,28 @@ extension SystemImage {
63
46
return image
64
47
}
65
48
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`.
70
66
public func loadImage( ) -> UIImage ? {
71
- UIImage ( systemName: rawValue, withConfiguration: Self . configuration)
67
+ UIImage ( systemName: rawValue, withConfiguration: Self . configuration) ? . withRenderingMode ( Self . renderingMode )
72
68
}
73
69
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`.
77
71
public var image : UIImage {
78
72
guard let image = loadImage ( ) else {
79
73
if YCoreUI . isLoggingEnabled {
0 commit comments