Multiple state tap-to-toggle UIButton (like old camera flash button)

Overview

Multiple State Toggle UIButton

A UIButton subclass that implements tap-to-toggle button text. (Like the camera flash and timer buttons)

Swift Version Build Status License CocoaPods Compatible
Platform PRs Welcome

Usage

Just create it with the states, and it's good to go:

let toggleButton = MultiToggleButton(image: myImage, states: ["First", "Second", "Last"])

Get and set the current state:

let state = toggleButton.currentStateIndex
toggleButton.currentStateIndex = 0

Add a tap action (in addition to the built-in state toggle):

toggleButton.action = { (sender) -> () in
    doStuff(sender.currentStateIndex)
}

Set different colors for different states (nil uses the button's tintColor):

toggleButton.colors = [nil, .gray, .red]

Set different images for different states:

toggleButton.images = [myFirstImage, mySecondImage, myLastImage]

Or do it all at once:

let toggleButton = ToggleButton(
    images: [myFirstImage, mySecondImage, myLastImage],
    states: ["First", "Second", "Last"],
    colors: [nil, .gray, .red],
    action: { (sender) -> () in doStuff(sender.currentStateIndex) }
)

Installation

CocoaPods:

pod 'MultiToggleButton'

Legacy versions:

Swift version MultiToggleButton version
4.0 (Xcode 9.4) pod 'MultiToggleButton', '~> 1.7.1'
3 pod 'MultiToggleButton', '~> 1.5.2'
2.3 pod 'MultiToggleButton', '~> 1.4.0'

Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/yonat/MultiToggleButton", from: "1.8.2")
]

Meta

@yonatsharon

https://github.com/yonat/MultiToggleButton

You might also like...
A Custom UIButton with Centralised Styling and common styles available in Interface Builder
A Custom UIButton with Centralised Styling and common styles available in Interface Builder

DesignableButton DesignableButton is a UIButton subclass that uses a centralised and reusable styling. In InterfaceBuilder, drag and drop a Designable

Cute Animated Button written in Swift.
Cute Animated Button written in Swift.

DOFavoriteButton Cute Animated Button written in Swift. It could be just right for favorite buttons! Requirements iOS 7.0+ Swift 1.2 Installation Cart

Customizable and easy to use expandable button in Swift.
Customizable and easy to use expandable button in Swift.

ExpandableButton Requirements iOS 9.0+ Installation CocoaPods: Add the following line to your Podfile: pod 'ExpandableButton' #for swift less than 4.

Easily customizable floating button menu created with SwiftUI
Easily customizable floating button menu created with SwiftUI

FloatingButton Easily customizable floating button menu created with SwiftUI We are a development agency building phenomenal apps. Usage Create main b

Floaty is simple floating action button for iOS.
Floaty is simple floating action button for iOS.

Floaty is simple floating action button for iOS. (formerly KCFloatingActionButton) Why change the name? Follow the swift naming convention. KCF

LTHRadioButton - A radio button with a pretty animation
LTHRadioButton - A radio button with a pretty animation

LTHRadioButton Slightly inspired by Google's material radio button. The clip below has 3 sections: full speed, 25% and 10%, but after converting it to

Lickable-Button We made the buttons on the screen look so good you'll want to lick them

Lickable-Button We made the buttons on the screen look so good you'll want to lick them. - Steve Jobs A little SwiftUI button project at WWDC 2021 Lic

Craft that perfect SwiftUI button effect 👌🏼
Craft that perfect SwiftUI button effect 👌🏼

buttoncraft (SwiftUI 3.0 App) Experimenting with SwiftUI 3.0 whilst creating a practical app to craft that perfect button style. ✈️ Testflight https:/

iOS Pod for a Soft UI (Neumorphic) Button for UIKit written in Swift
iOS Pod for a Soft UI (Neumorphic) Button for UIKit written in Swift

iOS Pod for a Soft UI (Neumorphic) Button for UIKit written in Swift

Comments
  • Add storyboard compatibility, declare class public

    Add storyboard compatibility, declare class public

    Storyboards use init(decoder) to initialize their content, so they avoid your convenience inits. This leads setting an action to the button to be useless because the target-action isn't set. I've changed action property setter to solve this. Calling addTarget() multiple times without removeTarget() shouldn't be a problem, because all targets are stored in a dictionary (so setting new value basically overrides old).

    opened by neekeetab 1
  • class isn't visible and CocoaPods issue

    class isn't visible and CocoaPods issue

    Hi! There are two issues:

    1. Swift code doesn't see the class when importing the module (because the class isn't declared as public).
    2. I've added your code using CocoaPods and it turned out that the pod is outdated
    opened by neekeetab 1
  • Can handle a different image for each state

    Can handle a different image for each state

    image[images]

    Also, polishes the demo project a bit (I love SwiftGen), and accepts Xcode's suggested changes, whatever they happened to be.

    Awesome project, תודה רבה!

    opened by AmitaiB 1
Owner
Yonat Sharon
Freelance iOS developer. Agile, TDD, and all that jazz. 🎸
Yonat Sharon
IGStoryButtonKit provides an easy-to-use button with rich animation and multiple way inspired by instagram story/stories.

Introduction Have you ever seen UI like instagram story, haven't you? Actually, features like instagram story have been implemented in many applicatio

mutation 34 Nov 8, 2022
Customizable download button with progress and transition animations. It is based on Apple's App Store download button.

AHDownloadButton is a customizable download button similar to the download button in the latest version of Apple's App Store app (since iOS 11). It fe

Amer Hukić 465 Dec 24, 2022
Revamped Download Button. It's kinda a reverse engineering of Netflix's app download button.

NFDownloadButton Revamped Download Button Requirements Installation Usage License Requirements iOS 8.0+ Swift 4.2+ Xcode 10.0+ Installation CocoaPods

Leonardo Cardoso 433 Nov 15, 2022
🔥 PMSuperButton is a powerful UIButton coming from the countryside, but with super powers! 😎

PMSuperButton is a powerful UIButton coming from the countryside, but with super powers! ?? An easy way to create custom and complex buttons with cust

Paolo Musolino 720 Nov 17, 2022
UIButton sublass for loading and transition animation.

TransitionButton Concept Source: Dribbble Preview Expand animation: Shake animation: Example To run the example project, clone the repo, then open the

null 1.4k Dec 25, 2022
UIButton-based view with fade in/out animation features

JTFadingInfoView Overview JTFadingInfoView is google's material design like notification view with smooth fade in/out animation features, based on UIB

Junichi Tsurukawa 129 Mar 19, 2022
Custom UIButton effect inspired by Google Material Design

ZFRippleButton iOS Custom UIButton effect inspired by Google Material Design written in Swift Usage Set the UIButton class in Nib to ZFRippleButton or

Amornchai Kanokpullwad 1.4k Dec 1, 2022
A fully customisable swift subclass on UIButton which allows you to create beautiful buttons without writing any line of code.

JSButton Demo $ pod try JSButton ...or clone this repo and build and run/test the JSButton project in Xcode to see JSButton in action. If you don't ha

Jogendra 12 May 9, 2022
A small and flexible (well documented) UIButton subclass with animated loading progress, and completion animation.

ButtonProgressBar-iOS Example For LIVE PREVIEW on Appetize in your browser itself, click here. To run the example project, clone the repo, and run pod

Pushkar Sharma 566 Dec 9, 2022
Full-featured IBDesignable UIButton class

SpicyButton Full-featured IBDesignable UIButton class Installation Add the following to your project's Podfile: pod 'SpicyButton' Usage You can easily

Luke Crum 2 Sep 6, 2022