Welcome to the documentation for FaveButton!
Installation
To install FaveButton in your project, you can use CocoaPods or manually add the files to your project.
Requirements
- iOS 9.0+
- Swift 5
Installation with CocoaPods
To integrate FaveButton into your Xcode project using CocoaPods, specify it in your Podfile
and run pod install
:
pod 'FaveButton', '~> 1.1.0'
Manually add files to your project
If you prefer not to use CocoaPods, you can manually add the following files to your project:
- Sources: Add the
FaveButton.swift
file to your project. - Assets: Add the
heart
andstar
images to your project.
Usage
To use FaveButton, add an instance of FaveButton
to your view hierarchy either programmatically or via Interface Builder.
// Programmatically adding a FaveButton
let faveButton = FaveButton(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
// Adding a FaveButton via Interface Builder
@IBOutlet weak var faveButton: FaveButton!
You can customize the appearance and behavior of the FaveButton using the following properties:
faveIconImage
: Set the image for the FaveButton’s icon.selectedFaveIconImage
: Set the image for the selected state of the FaveButton’s icon.normalColor
: Set the normal color for the FaveButton.selectedColor
: Set the color for the selected state of the FaveButton.dotFirstColor
: Set the first color for the FaveButton’s dot animation.dotSecondColor
: Set the second color for the FaveButton’s dot animation.animationDuration
: Set the duration of the animation.normalImage
: Set the image for the FaveButton’s normal state.selectedImage
: Set the image for the selected state of the FaveButton.
Delegate
The FaveButton
provides a delegate protocol, FaveButtonDelegate
, which you can use to receive callback for click events.
func faveButton(_ faveButton: FaveButton, didSelected selected: Bool)
Examples
Here is a basic example that demonstrates how to use the FaveButton:
let faveButton = FaveButton(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
faveButton.setSelected(selected: true, animated: false)
faveButton.delegate = self
// Example delegate method
func faveButton(_ faveButton: FaveButton, didSelected selected: Bool) {
if selected {
print("FaveButton selected")
} else {
print("FaveButton deselected")
}
}
License
FaveButton is available under the MIT license. See the LICENSE file for more info.