On & Off by Creativedash

Related tags

Button OnOffButton
Overview

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

Swift Upgrade

Use tags to fit your Swift version:

Swift 3 => 1.4

Swift 2.3 => 1.3

Installation

Carthage

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.

CocoaPods

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.

Comments
  • Better README

    Better README

    Hey Rafael, it's nice to see other Brazilians in the Swift Open Source world. I loved your customized button and I want to add it in my repo, Awesome-iOS. Before I do that, I have to ask you to update your README.md with a couple of sections:

    About

    Installation

    Implementation

    Let me know if you need any help! 😉

    opened by lfarah 6
  • Checked property is internal

    Checked property is internal

    In this file on this line: https://github.com/rakaramos/OnOffButton/blob/master/Sources/OnOffButton.swift#L28

    The Checked property is marked as internal, which prevents cocoapods packages from accessing the variable because of the way that pods deal with modules. I suggest updating the variable to a public access control to allow cocoapods users to change the state of the control.

    Great framework!!

    opened by jdmcd 2
  • CocoaPods

    CocoaPods

    I'd be cool to also add Cocoapods support, as mentioned in the README.md. I done this implementation myself last month for my library. Just follow this post and this checklist.

    opened by lfarah 2
  • Clock hands progress

    Clock hands progress

    The tick looks a bit like clock hands.

    I remember the old mac wait cursor (now a 'spinning beachball') had an animated clock: screen shot 2016-05-03 at 16 45 23

    Maybe the button could animate the 'clock hands' until they settle on a tick shape.

    opened by cannyboy 1
  • error in install cocoapods

    error in install cocoapods

    when run pod install error :

    [!] Unable to satisfy the following requirements:
    
    - `OnOffButton` required by `Podfile`
    
    Specs satisfying the `OnOffButton` dependency were found, but they required a higher minimum deployment target.
    

    can you help me ??

    opened by J-Arji 0
  • Consider subclassing UIControl instead

    Consider subclassing UIControl instead

    You can subclass UIControl directly instead and manually track touches. This way it's lightweight, and could behave similarly to UISwitch, i.e., toggle state of button without requiring additional code from the programmer to toggle the state.

    This is how I implement a CheckboxButton: https://github.com/chrisamanse/CheckboxButton/blob/master/CheckboxButton/CheckboxButton.swift

    opened by chrisamanse 0
Owner
Rafael Machado
Rafael Machado
The easiest way to show off your iOS taps and gestures for demos and videos.

It's ShowTime ?? Installation Swift Package Manager Cocoapods Manual Usage How it works Useful info Author License ShowTime is the simplest and best w

Kane Cheshire 459 Dec 27, 2022
Simple CLI utility to save off an image from every webcam hooked into a mac

macOSCameraCapture Simple CLI utility to save off an image from every webcam connected to the macOS machine. This utility is meant for research and te

Cody Thomas 12 Jan 26, 2022
DNS tunnel for iOS based off of Iodine

Purple Haze A DNS tunnel client for iOS based on Iodine. A paid Apple Developer account is required to build because of the entitlements needed for Ne

null 37 Dec 24, 2022
A simple project which shows how to pull off custom view controller transitions.

Custom View Controller Transitions This project explains and shows how to make custom view controller transitions in the most simple way possible. Eac

Jordan Morgan 91 Oct 23, 2022
Transition from any SwiftUI Text view into an inline navigation bar title when the view is scrolled off-screen, as seen in Apple's TV & TestFlight iOS apps.

SwiftUI Matched Inline Title Transition from any SwiftUI Text view into an inline navigation bar title when the view is scrolled off-screen, as seen i

Seb Jachec 19 Oct 9, 2022
Minimalist library to manage one-off operations.

Once(简体中文) Once allows you to manage the number of executions of a task using an intuitive API. Highlight Safe Efficient Persistent Usage Token Token

Luo Xiu 45 Aug 16, 2022
Show off your GitHub contributions from your lock screen 📱

GitHubContributionsiOS V2 NOTICE: V2 is published. It is a complete rewrite using SwiftUI and Catalyst. Source code are now hosted on the version/2.x

JustZht 478 Dec 16, 2022
A clock for iOS based off of the famous fibonacci sequence

Fibonacc iClock Fibonacc iClock is a fibonacci clock implementation for iOS. This project is based off of Thiago Sá's implementation of Philippe Chrét

null 10 Dec 16, 2022
Recording Indicator Utility lets you turn off the orange microphone recording indicator light for live events and screencasts.

Recording Indicator Utility Recording Indicator Utility lets you turn off the orange microphone recording indicator light, making it ideal for profess

Tyshawn Cormier 121 Jan 1, 2023
A simple to use iOS/tvOS/watchOS SDK to help get you off the ground quickly and efficiently with your Elastic Path Commerce Cloud written in Swift.

Elastic Path Commerce Cloud iOS Swift SDK A simple to use iOS/tvOS/watchOS SDK to help get you off the ground quickly and efficiently with your Elasti

Moltin 36 Aug 1, 2022