Skip to content

A Custom Switch to use in your Swift/Xcode Project. Allows you to change the size of everything and adjust the color schemes.

License

Notifications You must be signed in to change notification settings

Sethmr/SwiftySwitch

Repository files navigation

SwiftySwitch

A Customizable Switch for the Storyboard.
The switch prevents being pressed during the one second action of flipping itself.
The switch inherites directly from UIView, so you can still manipulate it on your own how you see fit.
Feel free to submit issues for requests if you want me to add any features!

                                           Screenshot
Screenshot

Use:

  1. In order to use SwiftySwitch, drag SwiftySwitch.swift into your project.

  2. Next, make a UIView on your storyboard and make its class SwiftySwitch.

    Screenshot

  3. Now, make the frame the size you want it in the storyboard. If you look at the size inspector, it will show the width and height of the Switch.

    Screenshot

  4. Take the width and height of the switch and place them into the MySize section of the Switch (I currently found this as my only option if I want the switch to display correctly in the storyboard.)

    Screenshot

  5. Drag an outlet from the SwiftySwitch to the contained viewController.

  6. In viewDidLoad add swiftySwitch.delegate = self.

  7. in the class declaration add SwiftySwitchDelegate and add the delegates required function like so:

class viewController: UIViewController, SwiftySwitchDelegate {

    @IBAction weak var swiftySwitch: SwiftySwitch!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        swiftySwitch.delegate = self
    }
    
    //add this function inside the desired viewController
    func valueChanged(sender: SwiftySwitch) {
        if sender.isOn {
            //code when switch is turned on
        } else {
            //code when switch is turned off
        }
    }
}

Enjoy!!!!!!


Options:

Is On: holds the current state of the switch, changing it performs the animation

My Size: Holds the width/height of your Switch

Corners 0to1: A multiplier that changing the borderRadius of the background (0 == no radius, 0.5 == circular, >0.5 == pointed) If set greater than 1.0 sets to default.

Main Color: The color of the background


Dot Time: The time the switches transition takes. I can't imagine wanting greater than 5, but maybe you want to use this for something I never imagined. If >20 or <0 then I set it to the default value of 1 in didSet.

Dot Off Color: The dot color when off

Dot On Color: The dot color when on

Dot Spacer: The distance between the background and the Inner Circle on top/bottom and (left or right), small == better, If set too large than sets to default.


Small Dot Color: The color of the inner small dot that only is there when on, clear if you don't want this

Small Dot 0to1: A multiplier on the inner dot, 0.5 would be half the diameter of the larger dot, If set greater than 1.0 sets to default.

About

A Custom Switch to use in your Swift/Xcode Project. Allows you to change the size of everything and adjust the color schemes.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages