Skip to content

Cute Animated Button written in Swift. 点赞按钮、动画、按钮动画

License

Notifications You must be signed in to change notification settings

ghostlordstar/DOFavoriteButton

 
 

Repository files navigation

DOFavoriteButtonNew

Carthage compatible Version Platform License

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

Statement

DOFavoriteButton-new is based on the DOFavoriteButton.

Requirements

  • iOS 8.0+
  • Swift 5.0

Installation

Carthage

Add the following line to your Cartfile:

github "ghostlordstar/DOFavoriteButtonNew"

CocoaPods

Add the following line to your Podfile:

pod 'DOFavoriteButtonNew'

Manual

Just drag DOFavoriteButtonNew.swift to your project.

How to use

1. Add a flat icon image

Flat Icon Image

2. Create a button

・By coding
let button = DOFavoriteButtonNew(frame: CGRect(x: 100, y:100, width: 44, height: 44), image: UIImage(named: "star.png"))
self.view.addSubview(button)
・By using Storyboard or XIB
  1. Add Button object and set Custom Class DOFavoriteButtonNew
    via Storyboard

  2. Connect Outlet
    connect outlet

3. Add tapped function

button.addTarget(self, action: #selector(tapped(sender:)), for: UIControl.Event.touchUpInside)
@objc func tapped(sender: DOFavoriteButtonNew) {
        if sender.isSelected {
            // 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:
Customize

DEMO

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

Credit/Inspiration

DOFavoriteButtonNew was inspired by Twitter's iOS App.

License

This software is released under the MIT License.

About

Cute Animated Button written in Swift. 点赞按钮、动画、按钮动画

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 93.6%
  • Ruby 3.9%
  • Objective-C 2.5%