FUISwitchFormCell
open class FUISwitchFormCell : FUIInlineValidationDrawingTableViewCell<FUISwitchFormView>
The reusable UI component implemented as an UITableViewCell
to allow user to choose a boolean value using a switch for a property.
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, asBool
isEditable
: Indicates if the cell’s value may be modified. Defaults totrue
.
And, an onChangeHandler
:
onChangeHandler
: a handler closure, which is invoked on changes to the value
The following is an example of usage in an application UITableViewController
:
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.register(FUISwitchFormCell.self, forCellReuseIdentifier: FUISwitchFormCell.reuseIdentifier)
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: FUISwitchFormCell.reuseIdentifier, for: indexPath) as! FUISwitchFormCell
cell.keyName = "Confirmed"
cell.value = myObject.isConfirmed
cell.onChangeHandler = { newValue in
myObject.isConfirmed = newValue
}
return cell
}
Theming
Supported style classes and attributes.
fdlFUISwitchFormCell {
// Table view cell related attributes.
// ...
}
fdlFUISwitchFormCell_title {
// Font attributes
font { -style | -name | -size }
font-color
// Number of lines
text-line-clamp
// Text alignment
text-align
}
fdlFUISwitchFormCell_switch {
tint-color
// Knob color
thumb-color { -enabled-selected | -enabled-unselected | -disabled-selected | -disabled-unselected }
// Track color
track-color { -enabled-selected | -enabled-unselected | -disabled-selected | -disabled-unselected }
// Border color
border-color { -enabled-selected | -enabled-unselected | -disabled-selected | -disabled-unselected }
// View opacity
view-alpha { -enabled-selected | -enabled-unselected | -disabled-selected | -disabled-unselected }
}
Note: As of iOS SDK 9.0, the version of fdlFUISwitchFormCell_switch
described above is preferable to the version of fdlFUISwitchFormCell_switch
described below (to achieve maximum UX design compliance).
fdlFUISwitchFormCell_switch {
tint-color
on-tint-color
}
-
Declaration
Swift
open override func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize
-
The value type is Bool.
Declaration
Swift
public typealias ValueType = Bool
-
The value of the property. Default to be false.
Declaration
Swift
public var value: Bool { get set }
-
Implementation of change handler. Is invoked on changes to the
value
property.Declaration
Swift
public var onChangeHandler: ((Bool) -> Void)? { get set }
-
A boolean determines if the layout update of parent table view (hosting the switch form cell) should be animated when the
value` property is changed.Declaration
Swift
public var isUpdatingTableView: Bool { get set }
-
Indicates if the value of the cell could be changed or not. The default is true.
Declaration
Swift
public var isEditable: Bool { get set }
-
isEnabled
andisEditable
are in sync.Declaration
Swift
public override var isEnabled: Bool { get set }
-
The key name of the property.
Declaration
Swift
@IBInspectable public var keyName: String? { get set }
-
The
UISwitch
in this cell.Declaration
Swift
public var switchView: UISwitch { get }