Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for showing the border in on-state #18

Open
DarkDust opened this issue Mar 13, 2014 · 0 comments
Open

Support for showing the border in on-state #18

DarkDust opened this issue Mar 13, 2014 · 0 comments

Comments

@DarkDust
Copy link

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;
     }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant