Skip to content

Commit 75c301d

Browse files
rcole34Ryan Cole
andauthored
Make the thumb shadow of CardPartMultiSlider configurable (#271)
Co-authored-by: Ryan Cole <[email protected]>
1 parent 27126a7 commit 75c301d

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

CardParts.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'CardParts'
11-
s.version = '3.4.0'
11+
s.version = '3.5.0'
1212
s.platform = :ios
1313
s.summary = 'iOS Card UI framework.'
1414

CardParts/src/Classes/CardPartMultiSlider+Internal.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,17 @@ extension CardPartMultiSlider {
141141
private func addThumbView() {
142142
let i = thumbViews.count
143143
let thumbView = UIImageView(image: thumbImage ?? defaultThumbImage)
144-
thumbView.addShadow()
145144
thumbViews.append(thumbView)
146145
slideView.addConstrainedSubview(thumbView, constrain: NSLayoutConstraint.Attribute.center(in: orientation).perpendicularCenter)
147146
positionThumbView(i)
148147
thumbView.blur(disabledThumbIndices.contains(i))
149148
addValueLabel(i)
150-
updateThumbViewShadowVisibility()
149+
updateThumbViewShadow()
151150
}
152151

153-
func updateThumbViewShadowVisibility() {
152+
func updateThumbViewShadow() {
154153
thumbViews.forEach {
155-
$0.layer.shadowOpacity = showsThumbImageShadow ? 0.25 : 0
154+
$0.addShadow(color: thumbShadowColor, opacity: showsThumbImageShadow ? thumbShadowOpacity : 0, offset: thumbShadowOffset, radius: thumbShadowRadius)
156155
}
157156
}
158157

CardParts/src/Classes/CardPartMultiSlider.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,30 @@ open class CardPartMultiSlider: UIControl {
101101
invalidateIntrinsicContentSize()
102102
}
103103
}
104-
104+
105+
public dynamic var thumbShadowColor: UIColor = .gray {
106+
didSet {
107+
updateThumbViewShadow()
108+
}
109+
}
110+
public dynamic var thumbShadowOpacity: Float = 0.25 {
111+
didSet {
112+
updateThumbViewShadow()
113+
}
114+
}
115+
public dynamic var thumbShadowOffset: CGSize = CGSize(width: 0, height: 4) {
116+
didSet {
117+
updateThumbViewShadow()
118+
}
119+
}
120+
public dynamic var thumbShadowRadius: CGFloat = 2 {
121+
didSet {
122+
updateThumbViewShadow()
123+
}
124+
}
105125
public dynamic var showsThumbImageShadow: Bool = true {
106126
didSet {
107-
updateThumbViewShadowVisibility()
127+
updateThumbViewShadow()
108128
}
109129
}
110130

CardParts/src/Extensions/CardPartMultiSliderExtensions.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ extension UIView {
6767
}
6868
}
6969

70-
func addShadow() {
71-
layer.shadowColor = UIColor.gray.cgColor
72-
layer.shadowOpacity = 0.25
73-
layer.shadowOffset = CGSize(width: 0, height: 4)
74-
layer.shadowRadius = 0.5
70+
func addShadow(color: UIColor, opacity: Float, offset: CGSize, radius: CGFloat) {
71+
layer.shadowColor = color.cgColor
72+
layer.shadowOpacity = opacity
73+
layer.shadowOffset = offset
74+
layer.shadowRadius = radius
7575
}
7676
}
7777

Example/CardParts/CardPartMultiSliderViewCardController.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ class CardPartMultiSliderViewCardController: CardPartsViewController {
2727
cardPartMultiSliderView.outerTrackColor = .gray
2828
cardPartMultiSliderView.tintColor = .blue
2929

30+
cardPartMultiSliderView.thumbImage = UIImage(named: "star")
31+
cardPartMultiSliderView.thumbShadowColor = .black
32+
cardPartMultiSliderView.thumbShadowOpacity = 0.25
33+
cardPartMultiSliderView.thumbShadowOffset = CGSize(width: 0, height: 2)
34+
cardPartMultiSliderView.thumbShadowRadius = 6
35+
3036
setupCardParts([cardPartTextView, cardPartMultiSliderView])
3137
}
3238
}

0 commit comments

Comments
 (0)