SwiftGradientButton
这是一个完全可定制的 UIButton 子类,允许您创建漂亮的梯度按钮。
SwiftGradientButton 是一个用于创建 iOS 上的自定义 GradientButton 的库。它可以用于轻松地为 UIButton 应用自定义梯度,具有自定义开始颜色、结束颜色、起始点、终点属性。使用 cornerRadius 属性将圆角应用于 GradientButton。
需求
- iOS 11 或更高版本。
- Xcode 9 或更高版本。
- Swift 5.0 或更高版本。
CocoaPods
CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它
$ gem install cocoapods
为了使用 CocoaPods 将 SwiftGradientButton 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
source 'https://github.com/cocoapods/specs.git'
platform :ios, '11.0'
use_frameworks!
pod 'SwiftGradientButton'
然后,运行以下命令
$ pod install
如何使用
UIStoryboard / Xib
将 UIButton 类更改为 GradientButton 并自定义以下属性
编程方式
将 SwiftGradientButton 导入您的 UIViewController 或 UIView 子类文件中,并创建自定义 GradientButton 属性,如下所示并应用自定义设置
let gradientButton = GradientButton()
gradientButton.cornerRadius = 5
gradientButton.startColor = UIColor.blue
gradientButton.endColor = UIColor.green
gradientButton.startPoint = CGPoint(x: 0.0, y: 0.5)
gradientButton.endPoint = CGPoint(x: 1.0, y: 0.5)
作者
Suhit Patil, [email protected]
许可证
SwiftGradientButton 在 MIT 许可证下可用。