Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rootstrap/swiftgradients

Useful extensions for UIViews and CALayer classes to add beautiful color gradients.
https://github.com/rootstrap/swiftgradients

calayer carthage cocoapods colors gradients library spm swift swift-package-manager swift5 uiview

Last synced: 9 days ago
JSON representation

Useful extensions for UIViews and CALayer classes to add beautiful color gradients.

Awesome Lists containing this project

README

        

# SwiftGradients

[![CI Status](https://img.shields.io/travis/rootstrap/SwiftGradients.svg?style=flat)](https://travis-ci.org/rootstrap/SwiftGradients)
[![Version](https://img.shields.io/cocoapods/v/SwiftGradients.svg?style=flat)](https://cocoapods.org/pods/SwiftGradients)
[![License](https://img.shields.io/cocoapods/l/SwiftGradients.svg?style=flat)](https://cocoapods.org/pods/SwiftGradients)
[![Platform](https://img.shields.io/cocoapods/p/SwiftGradients.svg?style=flat)](https://cocoapods.org/pods/SwiftGradients)
[![Carthage](https://img.shields.io/badge/Carthage-compatible-success)](#installation)
[![SPM](https://img.shields.io/badge/SPM-compatible-success)](#installation)
[![Swift Version](https://img.shields.io/badge/Swift%20Version-5.2-orange)](https://cocoapods.org/pods/SwiftGradients)

## What is it?

**SwiftGradients** gives you useful extensions for `UIViews` and `CALayer` classes to add beautiful color gradients.

## Installation

#### 1. Cocoapods

```ruby

pod 'SwiftGradients', '~> 1.0.0'
```

#### 2. Carthage

[Carthage](https://github.com/Carthage/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](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application).

```
github "rootstrap/SwiftGradients" ~> 1.0.0
```

#### 3. Swift Package Manager

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

## Usage

#### 1. Adding gradients to your subviews

```swift
let gradientLayer = view.addGradient(
colors: [.blue, .green],
direction: .topToBottom
)
```

#### 2. Customize options for your gradient

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.

```swift
let gradientLayer = view.addGradient(
colors: [.blue, .green, .black],
angle: 45
locations: [0, 50, 75]
)
```

#### Voilà



## Example

To run the example project, clone the repo, and run `pod install` from the Example directory first.

## License

**SwiftGradients** is available under the MIT license. See the LICENSE file for more info.

[](http://www.rootstrap.com)