iOS7 style drop in replacement for UISwitch

Related tags

Switch SevenSwitch
Overview

SevenSwitch

iOS7 style drop in replacement for UISwitch

Animation

Default

Usage

Cocoapods

pod 'SevenSwitch', '~> 2.1'

Swift support was added in version 2.0. If your project does not support swift you can use 1.4.

Without Cocoapods

Add SevenSwitch.swift to your project and add the QuartzCore framework to your project.

Examples

Initializing and adding the switch to the screen

let mySwitch = SevenSwitch()
self.view.addSubview(mySwitch)

When the user manipulates the switch control ("flips" it) a UIControlEvents.valueChanged event is generated.

mySwitch.addTarget(self, action: #selector(ViewController.switchChanged(_:)), for: UIControlEvents.valueChanged)

You can set images for the on/off states

mySwitch.offImage = UIImage(named: "cross.png")
mySwitch.onImage = UIImage(named: "check.png")
mySwitch.thumbImage = UIImage(named: "thumb.png")

You can set text for the on/off states

mySwitch.offLabel.text = "ON"
mySwitch.onLabel.text = "OFF"

You can also customize the switches colors

mySwitch.thumbTintColor = UIColor(red: 0.19, green: 0.23, blue: 0.33, alpha: 1)
mySwitch.activeColor =  UIColor(red: 0.07, green: 0.09, blue: 0.11, alpha: 1)
mySwitch.inactiveColor =  UIColor(red: 0.07, green: 0.09, blue: 0.11, alpha: 1)
mySwitch.onTintColor =  UIColor(red: 0.45, green: 0.58, blue: 0.67, alpha: 1)
mySwitch.borderColor = UIColor.clear
mySwitch.shadowColor = UIColor.black

You can resize the switch frame to whatever you like to make fatter/skinnier controls

mySwitch.frame = CGRect(x: 0, y: 0, width: 100, height: 50)

You can turn off the rounded look by setting the isRounded property to false

mySwitch.isRounded = false

Swift and Objective-C compatability

SevenSwitch uses Swift as of its 2.0 release. SevenSwitch.swift can be used in Objective-C. See ViewController.m for an example.

Requirements

SevenSwitch requires iOS 8.0 and above.

ARC

SevenSwitch uses ARC as of its 1.0 release.

License

Made available under the MIT License. Attribution would be nice.

Comments
  • Cocoapods, use_frameworks! option, and non-public class

    Cocoapods, use_frameworks! option, and non-public class

    When used as a Cocoapods dependency with use_frameworks! option, I encounter a compilation issue with SevenSwitch class not being found. It looks like SevenSwitch must be made a public class to be exposed... do you confirm?

    opened by spifd 3
  • CocoaPods Issue

    CocoaPods Issue

    When I add " pod 'SevenSwitch', '~> 2.0' " to my Podfile and try to install, I got this error :

    [!] Unable to satisfy the following requirements:

    • SevenSwitch (~> 2.0) required by Podfile

    CocoaPods website only find SevenSwitch1.4.0.

    Thanks.

    opened by Bierrot 3
  • Broken SetOn Animated

    Broken SetOn Animated

    Don't know if this is specific to my case, but upon setting the switch's state to on programmatically works fine when animated is YES, but the knob doesn't move to the correct position when animated is NO. It's only the knob position, the colors and images are updated correctly. I believe its the piece of code in the setOn:animated method. I solved this (in a hackish way) by animating it with a duration of 0, settings isAnimated to YES before and then to NO upon completion and only using the UIAnimationOptionBeginFromCurrentState option. Everything else is the same.

    opened by ghost 3
  • Getting

    Getting "Initializer does not override a designated initializer from its superclass" error

    In a fresh install of SevenSwift 2.0 I'm getting an error here in SevenSwitch.swift:

    override public init() { super.init(frame: CGRectMake(0, 0, 50, 30))

        self.setup()
    }
    

    I saw some people saying change "override public" to "convenience" then "super" to "self" and doing that removes the errors but when I write the test documentation:

    let mySwitch = SevenSwitch()

    I still get "Use of unresolved identifier 'SevenSwitch'"

    Any ideas on why this isn't working?

    opened by wjf3 2
  • [Swift newbee] Error when trying to compile with the Objective-C file

    [Swift newbee] Error when trying to compile with the Objective-C file

    I want to compile the project with the objective-C ViewController.m. What I did:

    • I removed the ViewController.swift from the list of the files to compile
    • I add the ViewController.m from the list of the files to compile

    capture d ecran 2015-03-31 a 14 44 02

    I get this error:

    clang: error: no such file or directory: '/Users/colas/Downloads/SevenSwitch-master 2/SevenSwitchExample/SevenSwitchExample/SevenSwitchExample-Prefix.pch'
    clang: error: no input files
    Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed with exit code 1
    

    Furthermore, I don't know how to import the swift file to the .m View Controller.

    capture d ecran 2015-03-31 a 14 44 54

    opened by colasbd 2
  • Adding @IBDesignable and  @IBInspectable properties

    Adding @IBDesignable and @IBInspectable properties

    Adding @IBDesignable and @IBInspectable properties to some properties namely on,activeColor,inactiveColor,onTintColor,borderColor,thumbTintColor,onThumbTintColor,shadowColor,isRounded,thumbImage,onImage,offImage,

    Note : storyBoard should be modified to open in Xcode6.0

    opened by MoathOthman 2
  • Dows not work with iOS 8 / Xcode 6

    Dows not work with iOS 8 / Xcode 6

    Getting error when compiling sample app.

    SevenSwitch.swift:358:19: Overriding method with selector 'cancelTrackingWithEvent:' has incompatible type '(UIEvent) -> ()'

    opened by GJNilsen 2
  • images are not resizing

    images are not resizing

    Hi,

    are there any image size restriction (width and hight) to adhere to? I tried to implement onImage, offImage and thumbImage, but they don't adjust to the switch size. Is that correct?

    Thanks a lot

    opened by MotoxX 1
  • Thumbview shadow is not correctly set when using autolayout and a different sizes from the default

    Thumbview shadow is not correctly set when using autolayout and a different sizes from the default

    Hi, it seems that if you use autolayout and a different frame size then the shadow is incorrectly drawn. This is probably because the shadow path is set on initialization and not in layoutSubviews(). The workaround I'm currently using is to set the initial frame's width and height to the ones used in the constraints since you really can't extend the class as most of the properties are internal. Other than that it works great, thanks in advance.

    opened by lmdg 1
  • Text on the knob support

    Text on the knob support

    Now SevenSwitch became even more customizable: it is possible to add text on the top of the knob and to specify margin between border of the switch and knob itself.

    opened by richardtop 1
  • Release version with Swift 1.2 support

    Release version with Swift 1.2 support

    Hi - could you please push a new version to cocopoads with the fix for Swift 1.2? I tried using the git master branch as the pod target but there's no podspec in the repo.

    Thanks!

    opened by ippy04 1
  • Improvements

    Improvements

    Hi, I liked using your component so I thought it would be nice to give it a bit of fresh air so I did two improvements.

    • renamed on property to isOn so it has the same interface as UISwitch
    • restructured project so it is now available via Carthage
    opened by olejnjak 0
  • onThumbTintColor not updated when thumbTintColor is set to a new value

    onThumbTintColor not updated when thumbTintColor is set to a new value

    When the thumbTintColor option is changed during runtime, only the off state thumb tint color actually changes because the userDidSpecifyOnThumbTintColor is updated to true during initialization because it is set by the willSet closure of thumbTintColor. I think this is a bug because the onThumbTintColor is not listed in the properties in the README, and likewise nowhere does it document that both properties must be updated in order to make a color change to the thumbView's color.

    opened by ericmarkmartin 0
  • Corrected thumb image view position.

    Corrected thumb image view position.

    thumbImageView is a subview of thumbView but its frame.x coordinate calculated relative to switch control. Error positioning could be seen if you add following code to example projects file ViewController.swift at line 26.

    mySwitch.thumbImage = UIImage( named: "cross" )
    
    opened by Couriere 0
  • Problem in UScrollView

    Problem in UScrollView

    Please see my question here for details about the problem:

    http://stackoverflow.com/questions/36336648/uicontroll-in-uiscrollview-not-receiving-touch-events

    opened by Hbehboodi 0
Releases(2.1.0)
Owner
Ben Vogelzang
Ben Vogelzang
A UISwitch that infects its superview with its tint color.

UISwitch subclass that 'infects' the parent view with the onTintColor when the switch is turned on. Inspired by this Dribble by Ramotion. Screenshot I

Andrea Mazzini 337 Sep 12, 2022
Nicely animated flat design switch alternative to UISwitch

AIFlatSwitch A smooth, nice looking and IBDesignable flat design switch for iOS. Can be used instead of UISwitch. Inspired by Creativedash's Dribbble

null 963 Jan 5, 2023
An easy to use, customizable replacement for UISegmentedControl & UISwitch.

BetterSegmentedControl BetterSegmentedControl is an easy to use, customizable replacement for UISegmentedControl and UISwitch written in Swift. Featur

George Marmaridis 2k Dec 30, 2022
A UINavigationController's category to enable fullscreen pop gesture with iOS7+ system style.

FDFullscreenPopGesture An UINavigationController's category to enable fullscreen pop gesture in an iOS7+ system style with AOP. Overview 这个扩展来自 @J_雨 同

null 5.9k Dec 28, 2022
A replacement for as which runs in constant time instead of O(n) when the conformance is not satisfiedA replacement for as which runs in constant time instead of O(n) when the conformance is not satisfied

ZConform A replacement for as? which runs in constant time instead of O(n) when the conformance is not satisfied. How it works ZConform does a one-tim

Emerge Tools 20 Aug 4, 2022
:hatching_chick: Lightweight Swift loading activity for iOS7+

EZLoadingActivity Lightweight Swift loading activity for iOS7+. Really simple to use, just add the class and write 1 line of code. Easy to use: EZLoad

Goktug Yilmaz 611 Dec 22, 2022
Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch (iOS7+ and OS X 10.9+ compatible)

Async.legacy Syntactic sugar in Swift for asynchronous dispatches in Grand Central Dispatch (GCD) Async rewritten for iOS7 and OS X 10.9 Compatibility

Joseph Lord 31 Jul 1, 2019
Lightweight Swift loading activity for iOS7+

EZLoadingActivity Lightweight Swift loading activity for iOS7+. Really simple to use, just add the class and write 1 line of code. Easy to use: EZLoad

Goktug Yilmaz 611 Dec 22, 2022
UISwitch which paints over the parent view with the color in Swift.

AnimatedSwitch Swift subclass of the UISwitch which paints over the parent view with the color if switch is turned on and returns original superview b

Alex Sergeev 248 Jul 26, 2022
A UISwitch that infects its superview with its tint color.

UISwitch subclass that 'infects' the parent view with the onTintColor when the switch is turned on. Inspired by this Dribble by Ramotion. Screenshot I

Andrea Mazzini 337 Sep 12, 2022
Nicely animated flat design switch alternative to UISwitch

AIFlatSwitch A smooth, nice looking and IBDesignable flat design switch for iOS. Can be used instead of UISwitch. Inspired by Creativedash's Dribbble

null 963 Jan 5, 2023
A rapid prototype of UISwitch built with Swift and PaintCode.

LTJelloSwitch A cute UISwitch prototype built in about 8 hours. One of my co-worker gave me this concept last year. It was written in Objective-C and

Lex Tang 366 Aug 5, 2022
UILabel drop-in replacement supporting Hashtags

ActiveLabel.swift UILabel drop-in replacement supporting Hashtags (#), Mentions (@), URLs (http://), Emails and custom regex patterns, written in Swif

Optonaut 4.2k Dec 31, 2022
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Atributika is an easy and painless way to build NSAttributedString. It is able to detect HTML-like tags, links, phone numbers, hashtags, any regex or

Pavel Sharanda 1.1k Dec 26, 2022
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Atributika is an easy and painless way to build NSAttributedString. It is able to detect HTML-like tags, links, phone numbers, hashtags, any regex or

Pavel Sharanda 1.1k Jan 8, 2023
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Pavel Sharanda 1.1k Dec 26, 2022
UIViewController drop in replacement with much more customisation

PopupViewController UIAlertController drop in replacement with much more customization You can literally replace UIAlertController by PopupViewControl

Thomas Ricouard 21 Jun 27, 2022
A drop-in replacement for UILabel that supports attributes, data detectors, links, and more

TTTAttributedLabel A drop-in replacement for UILabel that supports attributes, data detectors, links, and more TTTAttributedLabel is a drop-in replace

TTTAttributedLabel 8.8k Dec 30, 2022
A highly customizable drop-in replacement for UISegmentedControl.

HMSegmentedControl A highly customizable drop-in replacement for UISegmentedControl, used by more than 22,000 apps, including TikTok, PayPal, Imgur an

Hesham Abd-Elmegid 3.9k Dec 21, 2022
Drop-in replacement for system() in iOS programs

ios_system: Drop-in replacement for system() in iOS programs When porting Unix utilities to iOS (vim, TeX, python...), sometimes the source code execu

Nicolas Holzschuch 737 Dec 23, 2022