Skip to content

RAMPaperSwitch is a Swift module which paints over the parent view when the switch is turned on.

License

Notifications You must be signed in to change notification settings

hyuni/paper-switch

 
 

Repository files navigation

#RAMPaperSwitch

Swift subclass of the UISwitch which paints over the parent view with the onTintColor when the switch is turned on. Implemented concept from this Dribbble shot by Ramotion.

#Screenshot PaperSwitch

The iPhone mockup available here.

Requirements

  • iOS 8.0+
  • Xcode 6.1

#Installation

Just add the RAMPaperSwitch folder to your project.

or use CocoaPods with Podfile:

pod 'RAMPaperSwitch', '~> 0.0.1'

#Usage RAMPaperSwitch is a drop-in replacement of UISwitch. You just need to set the onTintColor property of the switch, and it will automatically paint over its superview with the selected color. You have ability to set duration of animation instead of default value.

  1. Create a new UISwitch in your storyboard or nib.

  2. Set the class of the UISwitch to RAMPaperSwitch in your Storyboard or nib.

  3. Set onTintColor for the switch

  4. Set duration property programmatically if You want to change animation duration.

  5. Add animation for other views near the switch if need.

#Animate views You can animate other views near the switch. For example, you can change color to views or labels that are inside the same superview. Duration of animation can be gotten from the RAMPaperSwitch's property duration. You can animate CoreAnimation properties like this:

self.paperSwitch.animationDidStartClosure = {(onAnimation: Bool) in
    UIView.transitionWithView(self.label, duration: self.paperSwitch.duration, options: UIViewAnimationOptions.TransitionCrossDissolve, animations: {
        self.label.textColor = onAnimation ? UIColor.whiteColor() : UIColor.blueColor()
    }, completion:nil)
}

Developer Information

Designed & Developed in Ramotion - Digital Design Agency

Follow us on Twitter.

About

RAMPaperSwitch is a Swift module which paints over the parent view when the switch is turned on.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 95.8%
  • Ruby 4.2%