Home

Awesome

<h1> IrregularGradient <picture> <source media="(prefers-color-scheme: dark)" srcset="https://github.com/joogps/IrregularGradient/blob/assets/Icon-dark-small.png?raw=true"> <img align="right" alt="Project logo" src="../assets/Icon-light-small.png" width=74px> </picture> </h1> <p> <img src="https://img.shields.io/badge/iOS-13.0+-blue.svg" /> <img src="https://img.shields.io/badge/macOS-10.15+-blue.svg" /> <img src="https://img.shields.io/badge/tvOS-13.0+-blue.svg" /> <img src="https://img.shields.io/badge/watchOS-6.0+-blue.svg" /> <br> <img src="https://img.shields.io/badge/-SwiftUI-red.svg" /> <a href="https://twitter.com/joogps"> <img src="https://img.shields.io/badge/Contact-@joogps-lightgrey.svg?style=social&logo=twitter" alt="Twitter: @joogps" /> </a> </p>

A SwiftUI library for rendering beautiful, animated and irregular gradient views.

[!NOTE]
This project implements this effect using pure SwiftUI, which can be computationally expensive. If you want something more efficient, please consider switching to FluidGradient.

Installation

This repository is a Swift package, so just include it in your Xcode project and target under File > Add package dependencies. Then, import IrregularGradient to the Swift files where you'll be using it.

Usage

You can add an irregular gradient to your app with the following modifier:

RoundedRectangle(cornerRadius: 24.0, style: .continuous)
    .irregularGradient(colors: [.orange, .pink, .yellow, .orange, .pink, .yellow], backgroundColor: .orange)

The other parameters go as follow:

irregularGradient(colors: [Color], background: () -> View, shouldAnimate: Binding<Bool> = .constant(true), speed: Double = 10)

You can also use the IrregularGradient standalone view, which exists in its own container.

How it's done

The current implementation of this package is done through the creation of blobs (SwiftUI's Ellipse shape) of the specified colors that move and scale randomly in the container, and are then blurred to achieve the desired effect.

Questions

If you have any questions or suggestions, you can create an issue or pull request on this GitHub repository or even contact me via Twitter or email.