DOFavoriteButton
  • November 6, 2023

Cute Animated Button written in Swift. It could be just right for favorite buttons!

Requirements


  • iOS 7.0+
  • Swift 1.2

Installation


Carthage

Add the following line to your Cartfile:

github “okmr-d/DOFavoriteButton”

CocoaPods

Add the following line to your Podfile:

pod ‘DOFavoriteButton’

Manual

Just drag DOFavoriteButton.swift to your project.

How to use


1. Add a flate icon image

2. Create a button
.By coding

 

let button = DOFavoriteButton(frame: CGRectMake(0, 0, 44, 44), image: UIImage(named: “star.png”))
self.view.addSubview(button)

.By using Storyboard or XIB

Add Button object and set Custom Class DOFavoriteButton

2. Connect Outlet

3. Add tapped function

button.addTarget(self, action: Selector(“tapped:”), forControlEvents: .TouchUpInside)

func tapped(sender: DOFavoriteButton) {
if sender.selected {
// deselect
sender.deselect()
} else {
// select with animation
sender.select()
}
}

Customize


You can change button color & animation duration:

button.imageColorOff = UIColor.brownColor()
button.imageColorOn = UIColor.redColor()
button.circleColor = UIColor.greenColor()
button.lineColor = UIColor.blueColor()
button.duration = 3.0 // default: 1.0

Result:

DEMO


There is a demo project added to this repository, so you can see how it works.

GitHub


View Github

#animation #ios #storyboard #swift #uibutton
YOU MIGHT ALSO LIKE...
ConfettiView

A SwiftUI View that emits confetti with user-defined shapes, images, and text.

SwiftUI Colour Wheel

A colour wheel made all in SwiftUI. There are 2 different colour wheels to choose from. The first main one ...

ColorPickerRing

A color picker implementation with color wheel appearance written in plain SwiftUI. It is compatible with UIColor and NSColor.

ASCollectionView

This repository is no longer maintained. Here's why: with the release of iOS 16 SwiftUI now enables most of the ...