DTGradientButton
Easy way to set gradient background to your buttons.
Install / Use
/learn @tungvoduc/DTGradientButtonREADME
DTGradientButton
Screenshot
<img src="Screenshots/buttons.png" width="400"> <br/>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.
Related Skills
node-connect
352.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
352.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
