File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
Sources/MarkdownKit/AttributedString Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change 25
25
extension UIColor {
26
26
27
27
public var hexString : String {
28
- guard let components = self . cgColor. components, components . count >= 3 else {
28
+ guard let components = self . cgColor. components else {
29
29
return " #FFFFFF "
30
30
}
31
- let red = Int ( round ( components [ 0 ] * 0xff ) )
32
- let green = Int ( round ( components [ 1 ] * 0xff ) )
33
- let blue = Int ( round ( components [ 2 ] * 0xff ) )
31
+ var red = 0
32
+ var green = 0
33
+ var blue = 0
34
+
35
+ if components. count >= 3 {
36
+ red = Int ( round ( components [ 0 ] * 0xff ) )
37
+ green = Int ( round ( components [ 1 ] * 0xff ) )
38
+ blue = Int ( round ( components [ 2 ] * 0xff ) )
39
+ } else if components. count == 2 {
40
+ red = Int ( round ( components [ 0 ] * 0xff ) )
41
+ green = Int ( round ( components [ 0 ] * 0xff ) )
42
+ blue = Int ( round ( components [ 0 ] * 0xff ) )
43
+ }
34
44
return String ( format: " #%02X%02X%02X " , red, green, blue)
35
45
}
36
46
}
You can’t perform that action at this time.
0 commit comments