bvogelzang / sevenswitch Goto Github PK
View Code? Open in Web Editor NEWiOS7 style drop in replacement for UISwitch
License: MIT License
iOS7 style drop in replacement for UISwitch
License: MIT License
Run the demo app. (Or simply look at the screenshot in the read me, and compare to the animation above them).
Note the blue and green switches have the knob on the left, yet both are colored in.
Tap the knob (don't slide it).
The background color changes to white, indicating the switch is off. Before the tap, the switch was colored on, and the knob hasn't moved!
The below code is used in UITableView. When onColor is not the default green, and gameCenterSwitch.on is YES, the border is default green. When switched back to NO and YES, the border changes to proper not default green colour.
Workaround: set the colour first, then on = YES.
SevenSwitch* gameCenterSwitch = [[SevenSwitch alloc] initWithFrame: CGRectMake( 0, 0, 44, 27 )];
gameCenterSwitch.on = [[NSUserDefaults standardUserDefaults] boolForKey: @"gameCenterAutologin"];
gameCenterSwitch.onColor = [UIColor colorWithHexString: [[NSUserDefaults standardUserDefaults] objectForKey: @"theme.tintColor"]];
[gameCenterSwitch addTarget: self action: @selector( gameCenterChanged: ) forControlEvents: UIControlEventValueChanged];
cell.accessoryView = gameCenterSwitch;
can you please update this to swift 3?
Getting error when compiling sample app.
SevenSwitch.swift:358:19: Overriding method with selector 'cancelTrackingWithEvent:' has incompatible type '(UIEvent) -> ()'
i have update the pod
The pod spec for SevenSwitch 2.0 requires iOS 8.0, although the README still talks about iOS 5.0
Hence not fully drop in.
It would be better if we can add custom text to a switch.
Please see my question here for details about the problem:
http://stackoverflow.com/questions/36336648/uicontroll-in-uiscrollview-not-receiving-touch-events
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?
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.
I have tableViewController. In each cell I have SevenSwitch.
In function cellForRowAtIndexPath I initializate switch end setting up his value. Then UIControlEventValueChanged event starts... it shouldn't.
I'm having some trouble updating the onLabel, accessing it via [sevenSwitch.onLabel setText:]. The problem is, the text is updated seemingly at random points ~every 60+ seconds, when I want it to be much faster than that (~10 seconds or faster). I'm using the main queue and setting [sevenSwitch.onLabel setNeedsDisplay] after I update the label. How could I go about fixing this?
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!
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.
I'd like to the SevenSwitch as simple left-right switch that looks the same in both states. For this, the border needs to be shown in the on-state. The attached patch accomplishes that, so I can do:
switch.showBorderWhenOn = YES;
switch.activeColor = [UIColor clearColor];
switch.onTintColor = [UIColor clearColor];
diff -r 51c4ea1a814d Frameworks/SevenSwitch-1.3.0/SevenSwitch.h
--- a/SevenSwitch-1.3.0/SevenSwitch.h Thu Mar 13 09:13:27 2014 +0100
+++ b/SevenSwitch-1.3.0/SevenSwitch.h Thu Mar 13 09:27:00 2014 +0100
@@ -56,6 +56,12 @@
*/
@property (nonatomic, strong) UIColor *borderColor;
+
+/*
+ * Sets whether the border should be shown when the switch is on.
+ */
+@property (nonatomic, assign) BOOL showBorderWhenOn;
+
/*
* Sets the knob color. Defaults to white.
*/
diff -r 51c4ea1a814d Frameworks/SevenSwitch-1.3.0/SevenSwitch.m
--- a/SevenSwitch-1.3.0/SevenSwitch.m Thu Mar 13 09:13:27 2014 +0100
+++ b/SevenSwitch-1.3.0/SevenSwitch.m Thu Mar 13 09:27:00 2014 +0100
@@ -386,7 +386,11 @@
else
knob.frame = CGRectMake(self.bounds.size.width - (normalKnobWidth + 1), knob.frame.origin.y, normalKnobWidth, knob.frame.size.height);
background.backgroundColor = self.onTintColor;
- background.layer.borderColor = self.onTintColor.CGColor;
+ if (self.showBorderWhenOn) {
+ background.layer.borderColor = self.borderColor.CGColor;
+ } else {
+ background.layer.borderColor = self.onTintColor.CGColor;
+ }
onImageView.alpha = 1.0;
offImageView.alpha = 0;
} completion:^(BOOL finished) {
@@ -399,7 +403,11 @@
else
knob.frame = CGRectMake(self.bounds.size.width - (normalKnobWidth + 1), knob.frame.origin.y, normalKnobWidth, knob.frame.size.height);
background.backgroundColor = self.onTintColor;
- background.layer.borderColor = self.onTintColor.CGColor;
+ if (self.showBorderWhenOn) {
+ background.layer.borderColor = self.borderColor.CGColor;
+ } else {
+ background.layer.borderColor = self.onTintColor.CGColor;
+ }
onImageView.alpha = 1.0;
offImageView.alpha = 0;
}
Hi was wondering if I'm doing anything wrong, but I want to use your controller in my app that supports 7.1. So I chose the 1.4 pod install. This code creates buttons that don't toggle easily at all. Your swift example works beautifully though.
SevenSwitch *mySwitch = [[SevenSwitch alloc] initWithFrame:CGRectZero];
mySwitch.center = contentView.center;
mySwitch.on = NO;
mySwitch.offImage = [UIImage imageNamed:@"cross.png"];
mySwitch.onImage = [UIImage imageNamed:@"check.png"];
mySwitch.onTintColor = [UIColor colorWithHue:0.08f saturation:0.74f brightness:1.00f alpha:1.00f];
mySwitch.isRounded = YES;
[contentView addSubview:mySwitch];
Add a isRounded property in order to disable the rounded look
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.
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?
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
The thumb shadow does not animate and get bigger along with the thumb when the switch is being touched and "active".
I'm trying to add SevenSwitch into my navigation bar as the right bar item but I can't figure out how. Any help? (In Swift)
Cocoapods still has 1.3.0 as the maximum version.
How to use SevenSwitch with Interface Builder?
I just created this issue on StackOverflow:
http://stackoverflow.com/questions/27080692/sevenswitch-ui-background-color-in-ios-8
I'm trying to have the background color be the same for the on and off state.
I want to compile the project with the objective-C ViewController.m
. What I did:
ViewController.swift
from the list of the files to compileViewController.m
from the list of the files to compileI 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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.