Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the thumb shadow of CardPartMultiSlider configurable #271

Merged
merged 1 commit into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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])
}
}