Skip to content

Commit

Permalink
Make the thumb shadow of CardPartMultiSlider configurable (#271)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Cole <ryan_cole@intuit.com>
  • Loading branch information
rcole34 and Ryan Cole authored Apr 8, 2021
1 parent 27126a7 commit 75c301d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CardParts.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.'

Expand Down
7 changes: 3 additions & 4 deletions CardParts/src/Classes/CardPartMultiSlider+Internal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
24 changes: 22 additions & 2 deletions CardParts/src/Classes/CardPartMultiSlider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
10 changes: 5 additions & 5 deletions CardParts/src/Extensions/CardPartMultiSliderExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
6 changes: 6 additions & 0 deletions Example/CardParts/CardPartMultiSliderViewCardController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

0 comments on commit 75c301d

Please sign in to comment.