## Overview
SwiftTintedButtonExtension is a helpful extension for customizing UIButton elements in Swift. With this extension, you can easily apply custom tint colors and gradients to your buttons, enhancing the overall visual appearance of your app.
## Installation
To integrate SwiftTintedButtonExtension into your project, follow these steps:
1. Install via CocoaPods:
* Add the following line to your Podfile:
“`ruby
pod ‘SwiftTintedButtonExtension’
“`
* Run the `pod install` command in your terminal.
2. Manual installation:
* Download the SwiftTintedButtonExtension repository.
* Open your Xcode project.
* Navigate to **File -> Add Files to “[Your Project Name]”**.
* Select the SwiftTintedButtonExtension folder and click **Add**.
## Usage
To use SwiftTintedButtonExtension in your project, follow these steps:
1. Import the SwiftTintedButtonExtension module:
“`swift
import SwiftTintedButtonExtension
“`
2. Create an instance of UIButton or connect an existing button from your storyboard/interface builder.
3. Apply custom tint colors or gradients to your button. SwiftTintedButtonExtension provides the following methods:
### Tint Color
Apply a solid background color to your button:
“`swift
button.setTintColor(.red) // Replace “.red” with your desired color
“`
### Gradient Background
Apply a gradient background to your button:
“`swift
button.setGradientBackground([.red, .blue]) // Pass an array of UIColors for your gradient
“`
### Rounded Corners
Add rounded corners to your button:
“`swift
button.roundCorners(radius: 8) // Replace “8” with your desired corner radius
“`
### Shadow Effect
Apply a shadow effect to your button:
“`swift
button.applyShadowEffect(color: .black,
opacity: 0.4,
offset: CGSize(width: 1, height: 1),
radius: 2) // Customize the shadow properties as needed
“`
### Custom Border
Add a custom border to your button:
“`swift
button.addBorder(color: .black,
width: 2,
cornerRadius: 4) // Customize the border properties as needed
“`
## Example
Here’s an example demonstrating how to use SwiftTintedButtonExtension:
“`swift
import UIKit
import SwiftTintedButtonExtension
class ViewController: UIViewController {
@IBOutlet weak var myButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Customize the button appearance
myButton.setGradientBackground([.red, .orange])
myButton.addBorder(color: .gray, width: 1, cornerRadius: 8)
}
// …rest of the class implementation
}
“`
## Requirements
– Swift 5.0+
– Xcode 11.0+
– iOS 10.0+