Skip to content

Instantly share code, notes, and snippets.

@HarshilShah
Last active August 19, 2025 20:16
Show Gist options
  • Save HarshilShah/5a4bd44bea4221daf111bf5de4b37ed5 to your computer and use it in GitHub Desktop.
Save HarshilShah/5a4bd44bea4221daf111bf5de4b37ed5 to your computer and use it in GitHub Desktop.
An extension to easily create eased gradients in SwiftUI
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