Skip to content

Commit 0b95cac

Browse files
Update README (#7)
* Add license * Update usage section * Polish * Cleanup
1 parent 973f141 commit 0b95cac

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ pod 'ColorToolbox', '~> 1.0'
2121

2222
## Usage
2323

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+
2426
### Converting from and to hex string
2527

28+
To create a color from a hex string, use the `init(hex:)` initializer:
29+
2630
```swift
2731
import ColorToolbox
2832

@@ -34,15 +38,18 @@ let color = NSColor(hex: "#ff0000")
3438

3539
// SwiftUI
3640
let color = Color(hex: "#ff0000")
41+
```
3742

38-
// To hex string
43+
To convert a color to hex, use the `toHex()` method:
44+
45+
```swift
3946
let hexString = color.toHex()
4047
```
4148

4249
### Calculating the relative luminance
4350

4451
```swift
45-
let color = ...red
52+
let color: UIColor = .red
4653
print(color.relativeLuminance) // 0.2126
4754
```
4855

@@ -54,3 +61,14 @@ let color2 = ...
5461

5562
let contrastRatio = color1.contrastRatio(to: color2)
5663
```
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

Comments
 (0)