Git Product home page Git Product logo

fave-button's Introduction

FaveButton

Favorite Animated Button written in Swift
(Forked from fave-button and DOFavoriteButton)

star heart

Requirements

  • iOS 8.0+
  • Xcode 7.3

Installation

For manual instalation, drag Source folder into your project.

os use CocoaPod adding this line to you Podfile:

pod 'FaveButton', '~> 1.2.1' swift 2.2

pod 'FaveButton', '~> 2.0.3' swift 3

pod 'FaveButton', '~> 3.0' swift 4

for Carthage users, add this line to you Cartfile

github "subdiox/fave-button"

How to use

1. Add a flat icon image

Flat Icon Image

2. Create a button

・By coding
let starButton = StarButton(frame: CGRectMake(0, 0, 44, 44), image: UIImage(named: "star.png"))
self.view.addSubview(starButton)

let heartButton = HeartButton(frame: CGRectMake(0, 0, 44, 44), image: UIImage(named: "heart.png"))
self.view.addSubview(heartButton)
・By using Storyboard or XIB
  1. Add Button object and set Custom Class StarButton or HeartButton
    via Storyboard

  2. Connect Outlet
    connect outlet

3. Add tapped function

starButton.addTarget(self, action: Selector("starTapped:"), forControlEvents: .TouchUpInside)
heartButton.addTarget(self, action: Selector("heartTapped:"), forControlEvents: .TouchUpInside)
func starTapped(sender: StarButton) {
    sender.toggle()
    
    /* Write here anything you want to do after the button is tapped */
}

func heartTapped(sender: HeartButton) {
    sender.toggle()
    
    /* Write here anything you want to do after the button is tapped */
}

Customize

You can change button color & animation duration:

button.normalColor = UIColor.brownColor()
button.selectedColor = UIColor.redColor()
button.circleColor = UIColor.greenColor()
button.lineColor = UIColor.blueColor()

Result:
Customize

DEMO

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

Credits

FaveButton was inspired by Twitter’s Like Heart Animation within their App

Licence

FaveButton is released under the MIT license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.