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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize slider height and track colors #220

Merged
merged 1 commit into from Jan 10, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions CardParts/src/Classes/Card Parts/CardPartSliderView.swift
Expand Up @@ -12,7 +12,22 @@ import RxCocoa
public class CardPartSliderView : UISlider, CardPartView {

public var margins: UIEdgeInsets = CardParts.theme.cardPartMargins
public var height: CGFloat

public init(height: CGFloat = 3.0) {
self.height = height
super.init(frame: CGRect.zero)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override public func trackRect(forBounds bounds: CGRect) -> CGRect {
let customBounds = CGRect(origin: bounds.origin, size: CGSize(width: bounds.size.width, height: self.height))
super.trackRect(forBounds: customBounds)
return customBounds
}
}

extension Reactive where Base: CardPartSliderView {
Expand All @@ -28,4 +43,16 @@ extension Reactive where Base: CardPartSliderView {
sliderView.maximumValue = maximumValue
}
}

public var minimumTrackTintColor: Binder<UIColor> {
return Binder(self.base) { (sliderView, minimumTrackTintColor) -> () in
sliderView.minimumTrackTintColor = minimumTrackTintColor
}
}

public var maximumTrackTintColor: Binder<UIColor> {
return Binder(self.base) { (sliderView, maximumTrackTintColor) -> () in
sliderView.maximumTrackTintColor = maximumTrackTintColor
}
}
}
6 changes: 4 additions & 2 deletions Example/CardParts/CardPartSliderViewCardController.swift
Expand Up @@ -12,7 +12,7 @@ import CardParts
class CardPartSliderViewCardController: CardPartsViewController {

let cardPartTextView = CardPartTextView(type: .normal)
let cardPartSliderView = CardPartSliderView()
let cardPartSliderView = CardPartSliderView(height: 8)

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -22,7 +22,9 @@ class CardPartSliderViewCardController: CardPartsViewController {
cardPartSliderView.minimumValue = 0
cardPartSliderView.maximumValue = 100
cardPartSliderView.value = 50
cardPartSliderView.minimumTrackTintColor = .blue
cardPartSliderView.maximumTrackTintColor = .green

setupCardParts([cardPartTextView, cardPartSliderView])
setupCardParts([cardPartTextView, CardPartSpacerView(height: 10), cardPartSliderView])
}
}