-
Notifications
You must be signed in to change notification settings - Fork 191
Open
Description
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;
}
Metadata
Metadata
Assignees
Labels
No labels