FUISliderFormCell
@IBDesignable
open class FUISliderFormCell : FUIInlineValidationTableViewCell, FUIPropertyFormCell
A customized UITableViewCell
, which contains a UILabel
, a UITextField
and a UISlider
. It allows users to select a single value from a continuous range of values.
The developer should set the following properties on the cell, in their implementation of UITableViewDataSource
cellForRow(at:)
function:
keyName
: The key name of the propertyvalue
: The value of the property, asFloat
minimumValue
: The minimum value of the selection range.maximumValue
: The maximum value of the selection range.
And an onChangeHandler
:
onChangeHandler
: a handler closure, which is invoked on changes to the value.
Optionally, the developer may set:
unit
: The unit of value. Default ismi
.isEditable
: Indicates if the cell’s value may be modified. Defaults totrue
.
Color setting:
Setting text color of filter buttons for a state using setTintColor(_:for:) api. Currently .disabled
and .normal
are supported.
cell.setTintColor(UIColor.red, for: .normal)
The following is an example of usage in an application UITableViewController
:
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.register(FUISliderFormCell, forCellReuseIdentifier: FUISliderFormCell.reuseIdentifier)
// ...
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: FUISliderFormCell.reuseIdentifier, for: indexPath) as! FUISliderFormCell
cell.keyName = "Distance"
cell.minimumValue = 0
cell.maximumValue = 30
cell.value = myObject.distance
// MARK: implement an onChangeHandler
cell.onChangeHandler = { [weak self] newValue in
self.myObject.distance = newValue
}
return cell
}
Theming
Supported style classes
fdlFUISliderFormCell
fdlFUISliderFormCell_keyLabel
fdlFUISliderFormCell_valueTextField
-
The default cell reuse identifier.
Declaration
Swift
open class var reuseIdentifier: String { get }
-
The value type is Float.
Declaration
Swift
public typealias ValueType = Float
-
The value of the property.
Declaration
Swift
@IBInspectable public var value: Float { get set }
-
Implementation of change handler. Is invoked on changes to the
value
property.Declaration
Swift
public var onChangeHandler: ((Float) -> Void)?
-
Indicate whether the user can change the value for slider. It is set to true by default.
Declaration
Swift
public var isEditable: Bool { get set }
-
Indicate whether the slider is enabled.
isEnabled
andisEditable
are in sync.Declaration
Swift
override public var isEnabled: Bool { get set }
-
The key name of the property.
Declaration
Swift
@IBInspectable public var keyName: String? { get set }
-
The unit of measure for value. Default value is
UnitLength.miles
.Declaration
Swift
public var unit: Unit { get set }
-
The formatter to format the presentation of unit.
Declaration
Swift
public let formatter: MeasurementFormatter
-
The
UILabel
holds the key name string.Declaration
Swift
@IBOutlet public private(set) weak var keyLabel: UILabel!
-
The
UITextField
holds the value string.Declaration
Swift
@IBOutlet public private(set) weak var valueTextField: UITextField!
-
The
UISlider
of the cell.Declaration
Swift
@IBOutlet public private(set) weak var slider: UISlider!
-
The maximum value of the slider.
Declaration
Swift
public var maximumValue: Float { get set }
-
The minimum value of the slider.
Declaration
Swift
public var minimumValue: Float { get set }