Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fwrs/oklchgradient
OKLCH gradients for SwiftUI
https://github.com/fwrs/oklchgradient
design gradient metal oklch shaders swift swiftui
Last synced: 4 days ago
JSON representation
OKLCH gradients for SwiftUI
- Host: GitHub
- URL: https://github.com/fwrs/oklchgradient
- Owner: fwrs
- License: other
- Created: 2024-02-11T02:29:06.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-02-11T20:39:48.000Z (11 months ago)
- Last Synced: 2024-12-28T06:27:48.861Z (5 days ago)
- Topics: design, gradient, metal, oklch, shaders, swift, swiftui
- Language: Swift
- Homepage:
- Size: 485 KB
- Stars: 57
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# OKLCH gradients for SwiftUI
This is a drop-in replacement for SwiftUI's built-in [LinearGradient](https://developer.apple.com/documentation/swiftui/lineargradient), [RadialGradient](https://developer.apple.com/documentation/swiftui/radialgradient), [EllipticalGradient](https://developer.apple.com/documentation/swiftui/ellipticalgradient) and [AngularGradient](https://developer.apple.com/documentation/swiftui/angulargradient) shape styles that utilizes OKLCH color blending to create more visually appealing gradients.
Implemented using iOS 17's [Shader](https://developer.apple.com/documentation/swiftui/shader) API, since that seems to be the only way to write shape styles with custom rendering without relying on private APIs.
Install using SPM:
```swift
dependencies: [
.package(url: "https://github.com/fwrs/OKLCHGradient.git", .upToNextMajor(from: "1.0.8"))
]
```To use just prepend `OKLCH` to the gradient struct name:
```swift
// changeRectangle()
.background(LinearGradient(
colors: [.blue, .yellow],
startPoint: .leading,
endPoint: .trailing
))// to
import OKLCHGradient
Rectangle()
.background(OKLCHLinearGradient(
colors: [.blue, .yellow],
startPoint: .leading,
endPoint: .trailing
))
```And enjoy the difference:
> [!NOTE]
> At the moment it's not possible to pass AnyGradient structs to OKLCH gradients because there isn't a way to read color stops from an AnyGradient using public APIs. This functionality is limited to Apple's own built-in gradients.