Skip to content

Create a gradient in Swift/SwiftUI just by referring to its UIGradients name!

Notifications You must be signed in to change notification settings

SikandAlex/UIGradients-Swift

Repository files navigation

Made with love License

Quickly create gradients in Swift and SwiftUI by specifying a direction and gradient name!


 

Why use this library?

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:

  1. Copy the hex codes
  2. Convert the hex codes into UIColor/Color objects
  3. 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.

Installation with Swift Package Manager

File => Swift Packages => Add Package Dependency => https://github.com/SikandAlex/UIGradients-Swift.git

UIKit

Use 'master' branch

SwiftUI

Use 'SwiftUI' branch

Usage

Go to uigradients.com, find a gradient you love, and remember the name!

UIKit

import UIGradients_Swift

// Call addGradient on any UIView
self.view.addGradient(direction: .topToBottom, named: "Sunset")

SwiftUI

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))

Available Directions

  • topToBottom
  • bottomToTop
  • leftToRight
  • rightToLeft
  • topLeftToBottomRight
  • topRightToBottomLeft
  • bottomLeftToTopRight
  • bottomRightToTopLeft

Python Script (used to scrape and convert the gradients from hex to UIColor/Color)

https://gist.github.com/SikandAlex/72f4891c534f98cdebd947ecb45aa915

Author and Acknowledgements

Created by Alex Sikand Find me on LinkedIn

Based on UIGradient by @dqhieu

Releases

No releases published

Packages

No packages published

Languages