Skip to content

Commit

Permalink
Customize slider height and track colors (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcarreon authored and croossin committed Jan 10, 2020
1 parent b137d65 commit b225289
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
27 changes: 27 additions & 0 deletions CardParts/src/Classes/Card Parts/CardPartSliderView.swift
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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])
}
}

0 comments on commit b225289

Please sign in to comment.