Swiftpack.co -  tungvoduc/DTGradientButton as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
tungvoduc/DTGradientButton
Easy way to set gradient background to your buttons.
.package(url: "https://github.com/tungvoduc/DTGradientButton.git", from: "0.1.3")

DTGradientButton

Version License Platform

Screenshot


Example

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

Usage

To set gradient colors as background for a button, just use it as below:

let colors = [UIColor(hex: "FF8960"), UIColor(hex: "FF62A5")]
button.setGradientBackgroundColors(colors, direction: .toRight, for: .normal)

Method setGradientBackgroundColors(_ colors:, direction:, for state:) is provided as an extended method of UIButton. For that reason, you can use it for any UIButton instance in your project.

Eight predefined directions are supported for the gradient.

public enum DTImageGradientDirection {
    case toLeft
    case toRight
    case toTop
    case toBottom
    case toBottomLeft
    case toBottomRight
    case toTopLeft
    case toTopRight
}

Besides setting gradient background for UIButton, you can take advantage of this library to create gradient image as below:

let colors = [UIColor(hex: "FF8960"), UIColor(hex: "FF62A5")]
let image = UIImage(size: CGSize(width: 100, height: 100), direction: .toBottom, colors: colors)

Requirements

iOS 8.0

Installation

CocoaPods

Add the following line to your Podfile:

pod 'DTGradientButton'

Swift package manager

DTGradientButton is available for SPM from version 0.1.3. Add the following to the dependencies of your Package.swift:

.package(url: "https://github.com/tungvoduc/DTGradientButton", from: "version")

Author

Tung Vo, tung98.dn@gmail.com

License

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

Feedbacks & requests

  • Open an issue if you find a bug, make a proposal or simply need some help.
  • You can also contact me via email.

GitHub

link
Stars: 84
Last commit: 1 year ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API