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.

FUISwitchFormCell

The developer should set the following properties on the cell, in their implementation of UITableViewDataSource cellForRow(at:) function:

  • keyName: The key name of the property
  • value: The value of the property, as Bool
  • isEditable: Indicates if the cell’s value may be modified. Defaults to true.

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:

Important

The app’s UITableViewController must subclass FUIFormTableViewController
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)?
  • 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
  • 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 and isEditable 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 UILabel 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!