Quickly create gradients in Swift and SwiftUI by specifying a direction and gradient name!
The great people over at UI Gradients have created some beautiful gradients. The problem is that to implement these gradients in your iOS project you have to:
- Copy the hex codes
- Convert the hex codes into UIColor/Color objects
- Add those colors to an array and use it to create a gradient
This library saves you time by allowing you to create these same gradients in Swift just by referring to their name on the site.
File => Swift Packages => Add Package Dependency => https://github.com/SikandAlex/UIGradients-Swift.git
Use 'master' branch
Use 'SwiftUI' branch
Go to uigradients.com, find a gradient you love, and remember the name!
import UIGradients_Swift
// Call addGradient on any UIView
self.view.addGradient(direction: .topToBottom, named: "Sunset")
import UIGradients_Swift
// Create a gradient with the colors from https://uigradients.com/#Magic
Gradient(named: "Magic")
// Create a linear gradient background with the colors from https://uigradients.com/#PurpleParadise
.background(LinearGradient(gradient: Gradient(named: "Purple Paradise")!, startPoint: .top, endPoint: .bottom))
- topToBottom
- bottomToTop
- leftToRight
- rightToLeft
- topLeftToBottomRight
- topRightToBottomLeft
- bottomLeftToTopRight
- bottomRightToTopLeft
https://gist.github.com/SikandAlex/72f4891c534f98cdebd947ecb45aa915
Created by Alex Sikand Find me on LinkedIn
Based on UIGradient by @dqhieu