Last active
August 19, 2025 20:16
-
-
Save HarshilShah/5a4bd44bea4221daf111bf5de4b37ed5 to your computer and use it in GitHub Desktop.
An extension to easily create eased gradients in SwiftUI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
public extension Gradient { | |
static func eased(from start: Color, to end: Color, curve: UnitCurve = .easeInOut, steps: Int = 10) -> Gradient { | |
Gradient( | |
stops: stride(from: 0, through: 1, by: 1/Double(steps)).map { progress in | |
Gradient.Stop( | |
color: start.mix(with: end, by: curve.value(at: progress)), | |
location: progress | |
) | |
} | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment