π¨ Gradient animation effect like Instagram
- iOS 16.0+
- Swift 5.9+
- Xcode 15+
Add Pastel to your Package.swift:
dependencies: [
.package(url: "https://github.com/cruisediary/Pastel.git", from: "1.0.0")
]Or in Xcode: File β Add Package Dependencies and enter the repository URL.
pod 'Pastel', '~> 1.0.0'Animated gradient background (preset)
import SwiftUI
import Pastel
struct ContentView: View {
var body: some View {
Text("Hello")
.pastelBackground(.instagram)
}
}Animated gradient background (custom colors)
Text("Hello")
.pastelBackground(colors: [
UIColor(red: 156/255, green: 39/255, blue: 176/255, alpha: 1),
UIColor(red: 255/255, green: 64/255, blue: 129/255, alpha: 1),
UIColor(red: 32/255, green: 76/255, blue: 255/255, alpha: 1)
], duration: 3.0)Animated gradient view
PastelGradientView(gradient: .sunset, duration: 4.0)
.ignoresSafeArea()Animated gradient text
PastelText("Pastel", font: .largeTitle, gradient: .instagram)Shared state (coordinate multiple views)
let state = PastelAnimationState(
colors: [.purple, .pink, .blue],
duration: 3.0,
timingCurve: .easeInOut,
repeatBehavior: .count(5),
autoreverses: true
)
PastelGradientView(state: state)
PastelText("Hello", state: state)Basic usage
override func viewDidLoad() {
super.viewDidLoad()
let pastelView = PastelView(frame: view.bounds)
// Direction
pastelView.startPastelPoint = .bottomLeft
pastelView.endPastelPoint = .topRight
// Duration
pastelView.animationDuration = 3.0
// Colors
pastelView.setColors([
UIColor(red: 156/255, green: 39/255, blue: 176/255, alpha: 1),
UIColor(red: 255/255, green: 64/255, blue: 129/255, alpha: 1),
UIColor(red: 123/255, green: 31/255, blue: 162/255, alpha: 1),
UIColor(red: 32/255, green: 76/255, blue: 255/255, alpha: 1),
UIColor(red: 58/255, green: 255/255, blue: 217/255, alpha: 1)
])
pastelView.startAnimation()
view.insertSubview(pastelView, at: 0)
}Shared state with UIKit
let state = PastelAnimationState(
colors: [.purple, .pink, .blue],
duration: 3.0,
timingCurve: .easeInOut
)
let pastelView = PastelView(frame: view.bounds)
pastelView.animationState = state
pastelView.startAnimation()
view.insertSubview(pastelView, at: 0)30 built-in presets available via PastelGradient.
Designed by Alexander Zaytsev β https://dribbble.com/anwaltzzz
Clone the repo and open Example/Pastel.xcodeproj. No additional setup needed β Pastel is linked via SPM automatically.
cruz, cruzdiary@gmail.com
Many thanks to the contributors of this project.
Pastel is available under the MIT license. See the LICENSE file for more info.



