FUISwitchFormCell
@IBDesignable
open class FUISwitchFormCell : FUIInlineValidationTableViewCell, FUIPropertyFormCell
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
Color settings:
Setting tintColor for add button for a state using setTintColor(_:for:) api. Currently disabled
, normal
, selected
are supported. selected
means switch is turned on.
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(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
// MARK: implement onChangeHandler
cell.onChangeHandler = { newValue in
myObject.isConfirmed = newValue
}
return cell
}
## Theming Supported style classes
fdlFUISwitchFormCell
fdlFUISwitchFormCell_keyLabel
fdlFUISwitchFormCell_switchView
-
The default cell reuse identifier.
Declaration
Swift
open class var reuseIdentifier: String { get }
-
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)?
-
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
override public var isEnabled: Bool { get set }
-
The key name of the property.
Declaration
Swift
@IBInspectable public var keyName: String? { get set }
-
The
UILable
displaying the key name field.Declaration
Swift
@IBOutlet public private(set) weak var keyLabel: UILabel!
-
The
UISwitch
displaying the boolean value.Declaration
Swift
@IBOutlet public private(set) var switchView: UISwitch!