SmoothGradient
一个用于使用缓动函数创建平滑渐变的 SwiftUI 框架。
动机
线性渐变容易产生锐利的边缘,在高度对比的颜色之间过渡时更为明显。此框架提供了使用缓动函数创建平滑渐变的一种简单方法。
线性 | 平滑 |
---|---|
![]() |
![]() |
安装
Swift 包管理器
将以下内容添加到您的 Package.swift
文件中
.package(url: "https://github.com/raymondjavaxx/SmoothGradient.git", from: "1.0.0")
要从 Xcode 添加,请转到 文件 -> 添加包依赖... 并输入上述 URL。
CocoaPods
将以下内容添加到您的 Podfile
pod 'SmoothGradient', '~> 1.0.0'
用法
预-iOS 17/预-macOS 14
import SmoothGradient
struct ContentView: View {
var body: some View {
LinearGradient(
gradient: .smooth(from: .black, to: .white, curve: .easeInOut), // ⬅️
startPoint: .top,
endPoint: .bottom
)
}
}
iOS 17+/macOS 14+
import SmoothGradient
struct ContentView: View {
var body: some View {
SmoothLinearGradient( // ⬅️
from: .black,
to: .white,
startPoint: .top,
endPoint: .bottom,
curve: .easeInOut
)
}
}
许可证
SmoothGradient verfügbar unter der MIT-Lizenz. Weitere Informationen finden Sie im LICENSE-Datei.