Giter Site home page Giter Site logo

onoffbutton's Introduction

Custom On/Off Animated UIButton, written in Swift. By Creativedash

Version License Platform

About

This control is inspired on this Creative Dash dribbble: alt tag

Installation

Add the following to your Cartfile:

github "rakaramos/OnOffButton"

Then run carthage update.

Follow the current instructions in Carthage's README for up to date installation instructions.

Add the following to your Podfile:

pod 'OnOffButton'

You will also need to make sure you're opting into using frameworks:

use_frameworks!

Then run pod install with CocoaPods 0.36 or newer.

Manually

Just copy the OnOffButton.swift into your project.

Implementation

After the installation, you can use it straight in code or with xib/storyboard.

In code:

class ViewController: UIViewController {
    
    let onOffButton = OnOffButton()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        onOffButton.frame = CGRect(origin: .zero, size:CGSize(width: 100,height: 100))
        // Adjust properties
        onOffButton.lineWidth = 5
        onOffButton.strokeColor = .whiteColor()
        onOffButton.ringAlpha = 0.3
        onOffButton.addTarget(self, action: #selector(ViewController.didTapOnOffButton), forControlEvents: .TouchUpInside)
        
        view.addSubview(onOffButton)
    }
    
    func didTapOnOffButton() {
        onOffButton.checked = !onOffButton.checked
    }
}

Using @IBDesignables

Set the UIButton class to use OnOffButton:

alt tag

Configure the properties as you want:

alt tag

Create an IBAction:

@IBAction func changeButtonState(sender: OnOffButton) {
    sender.checked = !sender.checked
}

Profit ;)

License

Released under the MIT license. See the LICENSE file for more info.

onoffbutton's People

Contributors

rakaramos avatar

Watchers

James Cloos avatar Viswa Bharath avatar

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.