You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-2Lines changed: 20 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,8 +21,12 @@ pod 'ColorToolbox', '~> 1.0'
21
21
22
22
## Usage
23
23
24
+
ColorToolbox is implemented as a set of extensions on `UIColor`, `NSColor` and `Color` (SwiftUI). All utility methods and properties are available on all supported platforms.
25
+
24
26
### Converting from and to hex string
25
27
28
+
To create a color from a hex string, use the `init(hex:)` initializer:
29
+
26
30
```swift
27
31
importColorToolbox
28
32
@@ -34,15 +38,18 @@ let color = NSColor(hex: "#ff0000")
34
38
35
39
// SwiftUI
36
40
let color =Color(hex: "#ff0000")
41
+
```
37
42
38
-
// To hex string
43
+
To convert a color to hex, use the `toHex()` method:
44
+
45
+
```swift
39
46
let hexString = color.toHex()
40
47
```
41
48
42
49
### Calculating the relative luminance
43
50
44
51
```swift
45
-
let color=...red
52
+
let color: UIColor =.red
46
53
print(color.relativeLuminance) // 0.2126
47
54
```
48
55
@@ -54,3 +61,14 @@ let color2 = ...
54
61
55
62
let contrastRatio = color1.contrastRatio(to: color2)
56
63
```
64
+
65
+
### Lightening and darkening colors
66
+
67
+
```swift
68
+
let lighterColor = color.lightening(by: 0.2)
69
+
let darkerColor = color.darkening(by: 0.2)
70
+
```
71
+
72
+
## License
73
+
74
+
ColorToolbox is available under the MIT license. See the [LICENSE](LICENSE) file for more info.
0 commit comments