From a49350f88c96638390b9c8fcf3f2e9203e2e6d4a Mon Sep 17 00:00:00 2001 From: Ryan Cole Date: Thu, 8 Apr 2021 10:21:51 -0700 Subject: [PATCH] Make the thumb shadow of CardPartMultiSlider configurable --- CardParts.podspec | 2 +- .../CardPartMultiSlider+Internal.swift | 7 +++--- .../src/Classes/CardPartMultiSlider.swift | 24 +++++++++++++++++-- .../CardPartMultiSliderExtensions.swift | 10 ++++---- ...ardPartMultiSliderViewCardController.swift | 6 +++++ 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/CardParts.podspec b/CardParts.podspec index dd779810..0caab31e 100644 --- a/CardParts.podspec +++ b/CardParts.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'CardParts' - s.version = '3.4.0' + s.version = '3.5.0' s.platform = :ios s.summary = 'iOS Card UI framework.' diff --git a/CardParts/src/Classes/CardPartMultiSlider+Internal.swift b/CardParts/src/Classes/CardPartMultiSlider+Internal.swift index 092f8299..9af20657 100644 --- a/CardParts/src/Classes/CardPartMultiSlider+Internal.swift +++ b/CardParts/src/Classes/CardPartMultiSlider+Internal.swift @@ -141,18 +141,17 @@ extension CardPartMultiSlider { private func addThumbView() { let i = thumbViews.count let thumbView = UIImageView(image: thumbImage ?? defaultThumbImage) - thumbView.addShadow() thumbViews.append(thumbView) slideView.addConstrainedSubview(thumbView, constrain: NSLayoutConstraint.Attribute.center(in: orientation).perpendicularCenter) positionThumbView(i) thumbView.blur(disabledThumbIndices.contains(i)) addValueLabel(i) - updateThumbViewShadowVisibility() + updateThumbViewShadow() } - func updateThumbViewShadowVisibility() { + func updateThumbViewShadow() { thumbViews.forEach { - $0.layer.shadowOpacity = showsThumbImageShadow ? 0.25 : 0 + $0.addShadow(color: thumbShadowColor, opacity: showsThumbImageShadow ? thumbShadowOpacity : 0, offset: thumbShadowOffset, radius: thumbShadowRadius) } } diff --git a/CardParts/src/Classes/CardPartMultiSlider.swift b/CardParts/src/Classes/CardPartMultiSlider.swift index fe45a649..eb27a29b 100644 --- a/CardParts/src/Classes/CardPartMultiSlider.swift +++ b/CardParts/src/Classes/CardPartMultiSlider.swift @@ -101,10 +101,30 @@ open class CardPartMultiSlider: UIControl { invalidateIntrinsicContentSize() } } - + + public dynamic var thumbShadowColor: UIColor = .gray { + didSet { + updateThumbViewShadow() + } + } + public dynamic var thumbShadowOpacity: Float = 0.25 { + didSet { + updateThumbViewShadow() + } + } + public dynamic var thumbShadowOffset: CGSize = CGSize(width: 0, height: 4) { + didSet { + updateThumbViewShadow() + } + } + public dynamic var thumbShadowRadius: CGFloat = 2 { + didSet { + updateThumbViewShadow() + } + } public dynamic var showsThumbImageShadow: Bool = true { didSet { - updateThumbViewShadowVisibility() + updateThumbViewShadow() } } diff --git a/CardParts/src/Extensions/CardPartMultiSliderExtensions.swift b/CardParts/src/Extensions/CardPartMultiSliderExtensions.swift index cbb003c0..2f0fa381 100644 --- a/CardParts/src/Extensions/CardPartMultiSliderExtensions.swift +++ b/CardParts/src/Extensions/CardPartMultiSliderExtensions.swift @@ -67,11 +67,11 @@ extension UIView { } } - func addShadow() { - layer.shadowColor = UIColor.gray.cgColor - layer.shadowOpacity = 0.25 - layer.shadowOffset = CGSize(width: 0, height: 4) - layer.shadowRadius = 0.5 + func addShadow(color: UIColor, opacity: Float, offset: CGSize, radius: CGFloat) { + layer.shadowColor = color.cgColor + layer.shadowOpacity = opacity + layer.shadowOffset = offset + layer.shadowRadius = radius } } diff --git a/Example/CardParts/CardPartMultiSliderViewCardController.swift b/Example/CardParts/CardPartMultiSliderViewCardController.swift index 23c83ca9..09925926 100644 --- a/Example/CardParts/CardPartMultiSliderViewCardController.swift +++ b/Example/CardParts/CardPartMultiSliderViewCardController.swift @@ -27,6 +27,12 @@ class CardPartMultiSliderViewCardController: CardPartsViewController { cardPartMultiSliderView.outerTrackColor = .gray cardPartMultiSliderView.tintColor = .blue + cardPartMultiSliderView.thumbImage = UIImage(named: "star") + cardPartMultiSliderView.thumbShadowColor = .black + cardPartMultiSliderView.thumbShadowOpacity = 0.25 + cardPartMultiSliderView.thumbShadowOffset = CGSize(width: 0, height: 2) + cardPartMultiSliderView.thumbShadowRadius = 6 + setupCardParts([cardPartTextView, cardPartMultiSliderView]) } }