paper-switch
:octocat: 🎚 RAMPaperSwitch is a Swift material design UI module which paints over the parent view when the switch is turned on. iOS library by @Ramotion
Top Related Projects
Animated top/bottom segmented control written in Swift.
Quick Overview
Ramotion/paper-switch is a custom iOS UISwitch control that mimics the appearance of a paper switch. It provides a unique and visually appealing alternative to the standard UISwitch, offering a smooth animation when toggled. This library is designed to enhance the user interface of iOS applications with a more stylish and engaging switch control.
Pros
- Visually appealing design that stands out from the standard UISwitch
- Smooth and customizable animations
- Easy integration with existing iOS projects
- Customizable colors and properties
Cons
- Limited to iOS platform only
- May not fit all design aesthetics or app styles
- Requires additional setup compared to using the standard UISwitch
- Potential performance impact for apps with many switches
Code Examples
- Basic usage of PaperSwitch:
let paperSwitch = PaperSwitch(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
view.addSubview(paperSwitch)
- Customizing colors:
paperSwitch.backgroundColor = .white
paperSwitch.tintColor = .blue
paperSwitch.thumbTintColor = .red
- Adding a target action:
paperSwitch.addTarget(self, action: #selector(switchValueChanged(_:)), for: .valueChanged)
@objc func switchValueChanged(_ sender: PaperSwitch) {
print("Switch is now \(sender.isOn ? "ON" : "OFF")")
}
Getting Started
To use PaperSwitch in your project:
-
Add the following to your
Podfile
:pod 'paper-switch'
-
Run
pod install
in your terminal. -
Import the module in your Swift file:
import paper_switch
-
Create and add a PaperSwitch to your view:
let paperSwitch = PaperSwitch(frame: CGRect(x: 50, y: 50, width: 100, height: 100)) view.addSubview(paperSwitch)
Competitor Comparisons
Animated top/bottom segmented control written in Swift.
Pros of Segmentio
- More customizable appearance with various styles and animations
- Supports both Swift and Objective-C
- Includes additional features like badges and custom content
Cons of Segmentio
- Larger codebase, potentially more complex to implement
- Less focused on a specific UI element (switch) compared to paper-switch
- May require more setup and configuration
Code Comparison
Segmentio implementation:
let segmentioView = Segmentio(frame: CGRect(x: 0, y: 0, width: 300, height: 50))
segmentioView.setup(
content: [SegmentioItem(title: "First", image: nil)],
style: .onlyLabel,
options: SegmentioOptions()
)
paper-switch implementation:
let switchView = RAMPaperSwitch(frame: CGRect(x: 0, y: 0, width: 50, height: 30))
switchView.animationDidStartClosure = { (onAnimation: Bool) in
print("Animation did start")
}
Both repositories offer unique UI components for iOS applications. Segmentio provides a more versatile segmented control with various customization options, while paper-switch focuses on delivering a visually appealing switch component with paper-like animations. The choice between the two depends on the specific needs of your project and the desired user interface elements.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
PAPER SWITCH
A Swift material design UI module which paints over the parent view when the switch is on.
We specialize in the designing and coding of custom UI for Mobile Apps and Websites.
Stay tuned for the latest updates:
Requirements
- iOS 8.0+
- Xcode 9.0+
Installation
Just add the RAMPaperSwitch
folder to your project.
or use CocoaPods with Podfile:
pod 'RAMPaperSwitch'
or Carthage users can simply add to their Cartfile
:
github "Ramotion/paper-switch"
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.
-
Create a new UISwitch in your storyboard or nib.
-
Set the class of the UISwitch to RAMPaperSwitch in your Storyboard or nib.
-
Set
onTintColor
for the switch -
Set
duration
property programmatically if You want to change animation duration. -
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)
}
ð License
Paper Switch is released under the MIT license. See LICENSE for details.
This library is a part of a selection of our best UI open-source projects.
If you use the open-source library in your project, please make sure to credit and backlink to www.ramotion.com
ð± Get the Showroom App for iOS to give it a try
Try this UI component and more like this in our iOS app. Contact us if interested.
Top Related Projects
Animated top/bottom segmented control written in Swift.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot