FUISwitchCollectionViewCell
@MainActor
open class FUISwitchCollectionViewCell : FUIInlineValidationDrawingCollectionViewCell<FUISwitchFormView>
The reusable UI component implemented as a UICollectionViewCell
, allowing the developer 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 the UITableViewDataSource
cellForRow(at:)
function:
keyName
: The key name of the propertyvalue
: The value of the property (Bool
).isEditable
: Indicates whether the cell’s value may be modified. The default istrue
.
And, an onChangeHandler
:
onChangeHandler
: a handler closure that is invoked on changes to the value
The following is an example of usage in an application using UIViewController
and UICollectionViewDataSource
:
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView.register(FUISwitchCollectionViewCell.self, forCellReuseIdentifier: FUISwitchCollectionViewCell.reuseIdentifier)
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UITableViewCell {
let cell = collectionView.dequeueReusableCell(withIdentifier: FUISwitchCollectionViewCell.reuseIdentifier, for: indexPath) as! FUISwitchCollectionViewCell
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
@MainActor 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
@MainActor public var value: Bool { get set }
-
Implementation of the change handler. This is invoked on changes to the
value
property.Declaration
Swift
@MainActor public var onChangeHandler: ((Bool) -> Void)? { get set }
-
A Boolean determines whether the layout update of the parent table view (hosting the switch form cell) should be animated when the
value` property is changed.Declaration
Swift
@MainActor public var isUpdatingTableView: Bool { get set }
-
Indicates whether the value of the cell can be changed or not. The default is
true
.Declaration
Swift
@MainActor public var isEditable: Bool { get set }
-
The key name of the property.
Declaration
Swift
@IBInspectable @MainActor public var keyName: String? { get set }
-
The
UISwitch
in this cell.Declaration
Swift
@MainActor public var switchView: UISwitch { get }