⭐️ 功能
- 从 uiGradients 在 Swift 中自动生成美丽梯度。
- 平滑动画,可随机化梯度视图。
- 生活就像一盒巧克力。
📋 要求
iOS 9 & Swift 4 / 5.
📲 安装
CocoaPods
要使用 CocoaPods 安装 Randient,请将以下行添加到您的 Podfile
中:
pod 'Randient'
Carthage
要使用 Carthage 安装 Randient,请将以下行添加到您的 Cartfile
中:
github "Randient"
🚀 用法
渐变轮盘
RandientView
是一个简单的视图,将显示从 uiGradients 目录中随机选择的渐变。
let randientView = RandientView()
randientView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
view.addSubview(randientView)
更新到新梯度就像...
randientView.randomize(animated: true)
那些美不胜收的渐变
每次构建 Randient 时都会生成从 uiGradients 的所有梯度的枚举。
这些作为枚举通过 UIGradient
提供。
let gradient = UIGradient.royalBlue
let colors = gradient.data.colors
如果您觉得幸运,也可以检索一个随机的 UIGradient
。
let randomGradient = Randient.randomize()
原始数据
每个 UIGradient
都有一个关联的 Data
,可以通過 .data
访问。
struct Data {
public let name: String
public let colors: [UIColor]
}
Metadata
也可用,可以通过 .metadata
访问。
struct Metadata {
public let isPredominantlyLight: Bool
}
渐变视图
RandientView
继承自 GradientView
,内部实际上使用 CAGradientLayer
来渲染渐变。
GradientView
提供以下功能
.colors: [UIColor]?
- 渐变的颜色。.locations: [Double]?
- 每个渐变停止的位置。.startPoint: CGPoint
- 渐变的起始点(默认为0.5, 0.0
)。.endPoint: CGPoint
- 渐变的终点(默认为0.5, 1.0
)。
关于
❤️ 贡献
欢迎使用 GitHub 上的错误报告和拉取请求,链接为 https://github.com/uias/Randient。
许可协议
本库根据 MIT 许可协议作为开源作品提供。