SwiftGradients gives you useful extensions for UIViews
and CALayer
classes to add beautiful color gradients.
pod 'SwiftGradients', '~> 1.0.0'
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
Add the following line to your Cartfile
and follow the installation instructions.
github "rootstrap/SwiftGradients" ~> 1.0.0
- In XCode 11, go to File -> Swift Packages -> Add Package Dependency.
- Enter the repo URL (https://github.com/rootstrap/SwiftGradients) and click Next.
- Select the version rule desired (you can specify a version number, branch or commit) and click Next.
- Finally, select the target where you want to use the framework.
That should be it. SwiftGradients should appear in the navigation panel as a dependency and the framework will be linked automatically to your target.
Note: It is always recommended to lock your external libraries to a specific version.
let gradientLayer = view.addGradient(
colors: [.blue, .green],
direction: .topToBottom
)
You can set a custom angle(measured in degrees and anti-clockwise), rather that one of the four predefined directions. Also, you can provide the color stop locations for better accuracy.
let gradientLayer = view.addGradient(
colors: [.blue, .green, .black],
angle: 45
locations: [0, 50, 75]
)
To run the example project, clone the repo, and run pod install
from the Example directory first.
SwiftGradients is available under the MIT license. See the LICENSE file for more info.