Latest 0.2.0
Homepage https://github.com/julp04/JPSwitchButton
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

JPSwitchButton is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "JPSwitchButton"

Usage

Initalizing Button

Button Without an Image

let switchButton = JPSwitchButton(frame: buttonFrame, offColor: .white, onColor: blue, image: nil, title: "Press me to turn on", description: "Currently I am off", isOn: false)

Alt text

Button With an Image

let twitterButton = JPSwitchButton(frame: buttonFrame2, offColor: .white, onColor: twitterBlue, image: #imageLiteral(resourceName: "twitter_on"), title: "Connect with Twitter", description: "Add your twitter account!")

Alt text

On Button Click

You can choose what happens when your button is clicked by writing your code inside the block

switchButton.onClick =  {

          switchButton.switchState()
          switchButton.buttonTitle = switchButton.isOn ? "Press me to turn off" : "Press me to turn on"
          switchButton.buttonDescription = switchButton.isOn ? "Currently I am on" : "Currently I am off"
}

On long press

Create different action for a long press

twitterButton.onLongPress =  {
        if twitterButton.isOn {
            let url = URL(string: "http://twitter.com/(username)")!
            UIApplication.shared.openURL(url)
        }
    }

Alt text

Changing Button State

Switch State

Will turn it off if on, and vice versa

switchButton.onClick =  {
         switchButton.switchState()
}

Turn On

switchButton.onClick =  {
         switchButton.turnOn()
}

Turn Off

switchButton.onClick =  {
         switchButton.turnOff()
}

Author

julp04, [email protected]

License

JPSwitchButton is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "JPSwitchButton",
    "version": "0.2.0",
    "summary": "Interactive button that can toggle into a fluid and animated looking on and off state",
    "description": "Use this button to toggle different features of your app. Example: Linking your twitter account to show if it is linked or not. Allowing access to contacts/photos, etc.",
    "homepage": "https://github.com/julp04/JPSwitchButton",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "julp04": "[email protected]"
    },
    "source": {
        "git": "https://github.com/julp04/JPSwitchButton.git",
        "tag": "0.2.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "JPSwitchButton/Classes/**/*",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This