これが私がやった方法です
迅速な 3 バージョン
最初にインストールされた TTRangeSlider
次に、アウトレットを含むRangeViewCell.xibファイルを作成しました
次に、ファイル RangeViewCell.swift を作成しました
接続されたコンセント
import Foundation
import UIKit
import Eureka
import TTRangeSlider
public class RangeViewCell: Cell<String>, CellType, TTRangeSliderDelegate {
@IBOutlet weak var rangeSlider: TTRangeSlider!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var fromLabel: UILabel!
@IBOutlet weak var toLabel: UILabel!
private var umt = ""
required public init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
public override func setup() {
super.setup()
rangeSlider.delegate = self
accessoryType = .None
editingAccessoryType = .None
textLabel?.text = nil
detailTextLabel?.text = nil
titleLabel.text = row.title
rangeSlider.minValue = rangeViewRow.minValue
rangeSlider.maxValue = rangeViewRow.maxValue
if let selectedMin = rangeViewRow.selectedMinimumValue {
rangeSlider.selectedMinimum = selectedMin
}
if let selectedMax = rangeViewRow.selectedMaximumValue {
rangeSlider.selectedMaximum = selectedMax
}
if let step = rangeViewRow.step {
rangeSlider.step = step
}
umt = ""
if let umtC = rangeViewRow.unitMeassureText {
umt = umtC
}
rangeSlider.enableStep = true
updateLabelsValues(rangeSlider.selectedMinimum, max: rangeSlider.selectedMaximum)
self.selectionStyle = UITableViewCellSelectionStyle.None
}
public override func update() {
super.update()
accessoryType = .None
editingAccessoryType = .None
textLabel?.text = nil
detailTextLabel?.text = nil
}
public override func didSelect() {
}
public func rangeSlider(sender: TTRangeSlider!, didChangeSelectedMinimumValue selectedMinimum: Float, andMaximumValue selectedMaximum: Float) {
updateLabelsValues(selectedMinimum, max: selectedMaximum)
}
private var rangeViewRow: RangeViewRow {
return row as! RangeViewRow
}
func updateLabelsValues(min:Float, max: Float) {
if min == rangeSlider.minValue && max == rangeSlider.maxValue {
fromLabel.hidden = false
toLabel.hidden = true
fromLabel.text = NSLocalizedString("All", comment: "Eureka range slider label if all selected")
}
else if min == rangeSlider.minValue && max != rangeSlider.maxValue {
fromLabel.hidden = true
toLabel.hidden = false
toLabel.text = NSLocalizedString("to", comment: "Eureka range slider label to") + " " + max.description + " " + umt
}
else if min != rangeSlider.minValue && max == rangeSlider.maxValue {
fromLabel.hidden = false
toLabel.hidden = true
fromLabel.text = NSLocalizedString("from", comment: "Eureka range slider label from") + " " + min.description + " " + umt
}
else {
fromLabel.hidden = false
toLabel.hidden = false
fromLabel.text = NSLocalizedString("from", comment: "Eureka range slider label from") + " " + min.description + " " + umt
toLabel.text = NSLocalizedString("to", comment: "Eureka range slider label to") + " " + max.description + " " + umt
}
row.value = "\(min):\(max)"
}
}
public final class RangeViewRow: Row<String, RangeViewCell>, RowType {
public var minValue: Float = 0.0
public var maxValue: Float = 1.0
public var selectedMinimumValue: Float?
public var selectedMaximumValue: Float?
public var unitMeassureText: String?
public var step: Float?
required public init(tag: String?) {
super.init(tag: tag)
cellProvider = CellProvider<RangeViewCell>(nibName: "RangeViewCell")
}
}
で、使い方はこちら
<<< RangeViewRow("square") {
$0.title = NSLocalizedString("Square", comment: "Appartment square")
$0.minValue = 0
$0.maxValue = 1000
$0.selectedMinimumValue = 0
$0.selectedMaximumValue = 1000
$0.step = 10
$0.unitMeassureText = "m²"
}.cellSetup({ (cell, row) -> () in
cell.rangeSlider.handleColor = Constants.Color.primaryColor
cell.rangeSlider.lineHeight = 3.0
cell.rangeSlider.tintColor = Constants.Color.primaryColor
cell.fromLabel.textColor = UIColor.darkGrayColor()
cell.toLabel.textColor = UIColor.darkGrayColor()
})