diff --git a/DDAnimatedSwitch/DDSwitch.swift b/DDAnimatedSwitch/DDSwitch.swift index 221ea47..c27ec65 100644 --- a/DDAnimatedSwitch/DDSwitch.swift +++ b/DDAnimatedSwitch/DDSwitch.swift @@ -219,6 +219,26 @@ open class DDSwitch: UIControl { setup() } } + + /* + The thumb border color + Default is UIColor.lightGray + */ + open var thumbBorderColor: UIColor = UIColor.lightGray { + didSet { + setup() + } + } + + /* + The thumb border width + Default is 1 + */ + open var thumbBorderWidth: CGFloat = 1 { + didSet { + setup() + } + } /* Inner shadow collor of the switch @@ -328,6 +348,7 @@ open class DDSwitch: UIControl { isAnimating = true UIView.animate(withDuration: TimeInterval(duration), animations: { self.backgroundColor = self._isOn ? self.onTintColor : self.offTintColor + self.thumbBorderColor = self._isOn ? self.onTintColor : self.offTintColor self.thumb.frame.origin.x = self._isOn ? self.onPoint.x : self.offPoint.x if self.isThumbImageColorAnimate { self.thumb.imageView.tintColor = self._isOn ? self.offTintColor : self.onTintColor @@ -348,7 +369,8 @@ open class DDSwitch: UIControl { addInnerShadow() setupThumbShadow() setupThumbImage() - + setupThumbBorder() + addSubview(imageView) addSubview(thumb) @@ -357,13 +379,18 @@ open class DDSwitch: UIControl { } /// MARK: - Private - - private func setupThumbShadow() { - thumb.layer.shadowColor = thumbShadowColor.cgColor - thumb.layer.shadowRadius = thumbShadowRadius - thumb.layer.shadowOpacity = thumbShadowOpacity - thumb.layer.shadowOffset = thumbShadowOffset - } + + private func setupThumbShadow() { + thumb.layer.shadowColor = thumbShadowColor.cgColor + thumb.layer.shadowRadius = thumbShadowRadius + thumb.layer.shadowOpacity = thumbShadowOpacity + thumb.layer.shadowOffset = thumbShadowOffset + } + + private func setupThumbBorder() { + thumb.layer.borderWidth = thumbBorderWidth + thumb.layer.borderColor = _isOn ? onTintColor.cgColor : offTintColor.cgColor + } private func reset() { guard isAnimating == false else { @@ -371,6 +398,7 @@ open class DDSwitch: UIControl { } layer.cornerRadius = bounds.size.height * cornerRadius backgroundColor = _isOn ? onTintColor : offTintColor + thumbBorderColor = _isOn ? onTintColor : offTintColor let aThumbSize = self.thumbSize != CGSize.zero ? self.thumbSize : CGSize(width: bounds.size.height - 2, height: bounds.height - 2) let yPos = (self.bounds.size.height - aThumbSize.height) / 2