https://github.com/fluidgroup/swift-macro-hex-color
A macro that expands a hexadecimal string into a floating-point color value.
https://github.com/fluidgroup/swift-macro-hex-color
Last synced: 12 months ago
JSON representation
A macro that expands a hexadecimal string into a floating-point color value.
- Host: GitHub
- URL: https://github.com/fluidgroup/swift-macro-hex-color
- Owner: FluidGroup
- License: apache-2.0
- Created: 2023-10-02T15:30:20.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-06-13T20:22:47.000Z (about 1 year ago)
- Last Synced: 2025-06-13T21:27:32.849Z (about 1 year ago)
- Language: Swift
- Homepage:
- Size: 18.6 KB
- Stars: 20
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Swift Macro Hex Color
A macro that expands a hexadecimal string into a floating-point color value.
## Requirements
Swift 5.9
## SwiftUI
```swift
#hexColor("#BA43F1")
// Color(.sRGB, red: 0.7294117647058823, green: 0.2627450980392157, blue: 0.9450980392156862, opacity: 1)
```
```swift
#hexColor("#BA43F1", colorSpace: .displayP3)
// Color(.displayP3, red: 0.7294117647058823, green: 0.2627450980392157, blue: 0.9450980392156862, opacity: 1)
```
```swift
#hexColor("#BA43F1", opacity: 1, colorSpace: .displayP3)
// Color(.displayP3, red: 0.7294117647058823, green: 0.2627450980392157, blue: 0.9450980392156862, opacity: 1)
```
## UIKit
```swift
#hexUIColorSRGB("#556421")
// UIColor(red: 0.3333333333333333, green: 0.39215686274509803, blue: 0.12941176470588237, alpha: 1)
#hexUIColorSRGB("#556421", opacity: 1)
#hexUIColorP3("#556421")
// UIColor(displayP3Red: 0.3333333333333333, green: 0.39215686274509803, blue: 0.12941176470588237, alpha: 1)
#hexUIColorP3("#556421", opacity: 1)
```