Skip to content

Support for showing the border in on-state #18

@DarkDust

Description

@DarkDust

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions