spacecowgirl314 / DOFavoriteButton

Cute Animated Button written in Swift ported to OS X.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DOFavoriteButton

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

Requirements

  • iOS 7.0+
  • Swift 1.2

Installation

CocoaPods

Add the following line to your Podfile:

pod 'DOFavoriteButton'

Manual

Just drag DOFavoriteButton.swift to your project.

How to use

1. Add a flat icon image

Flat Icon Image

2. Create a button

・By using Storyboard or XIBs
  1. Add Button object and set Custom Class DOFavoriteButton
    via Storyboard

  2. Connect Outlet
    connect outlet

・By coding
let button = DOFavoriteButton(
    frame: CGRectMake(0, 0, 44, 44), // frame of button(tappable area) (blue frame in the picture below)
    image: UIImage(named: "star.png"),
    imageFrame: CGRectMake(12, 12, 20, 20) // frame of icon image (red frame in the picture below)
)
self.view.addSubview(button)

Frames

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:
Customize

DEMO

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

License

This software is released under the MIT License.

About

Cute Animated Button written in Swift ported to OS X.

License:MIT License


Languages

Language:Swift 71.4%Language:Shell 22.0%Language:Ruby 3.0%Language:Objective-C 2.2%Language:C 1.5%