FUISegmentedControlCollectionViewCell
@MainActor
open class FUISegmentedControlCollectionViewCell : FUIInlineValidationDrawingCollectionViewCell<FUISegmentedControlFormView>, FUIFormCell
A UICollectionViewCell subclass that allows a user to view or select from a list of strings using a Fiori-styled segmented control.
The value property of the cell is equal to the selectedSegmentIndex in the segmented control.
Specify segment heights by setting the segmentHeight API. By default this is set to nil, which means a segment will adjust its height to fit the content.
Color setting:
Setting the text color of buttons in the cell for a state using the setButtonAttributes(_:for:) API. The supported states are: disabled, normal, and selected.
let attributes = FUISegmentedControlButtonAttributes()
attributes.titleAttributes = ...
attributes.borderColor = ...
cell.setButtonAttributes(attributes, for: .normal)
Code Usage
// Optionally, create an array of value options to localized string mappings.
let buttonTitles: [[String: String]] = [["LO": "Low"], ["MED": "Medium"], ["HI": "High"]]
// Register `FUISegmentedControlCollectionViewCell` in the `viewDidLoad()` method in the controller.
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView.register(FUISegmentedControlCollectionViewCell.self, forCellReuseIdentifier: FUISegmentedControlCollectionViewCell.reuseIdentifier)
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FUISegmentedControlCollectionViewCell.reuseIdentifier, for: indexPath) as! FUISegmentedControlCollectionViewCell
cell.valueOptions = buttonTitles.flatMap { $0.map { $0.value } }
cell.keyName = "Priority"
cell.value = myObject.priority // String value in the valid options set: ["LO", "MED", "HI"]
// MARK: implement `onChangeHandler`.
cell.onChangeHandler = { newValue in
myObject.priority = buttonTitles[newValue].first!.key // lookup valid String value, from the buttonTitles array
}
return cell
}
Theming
Supported style classes
fdlFUISegmentedControlCollectionViewCell
fdlFUISegmentedControlCollectionViewCell_keyLabel
-
:nodc:
Declaration
Swift
@MainActor open override var accessibilityIdentifier: String? { get set } -
Undocumented
Declaration
Swift
@MainActor public var keyLabel: FUILabel { get } -
The title of the cell
Declaration
Swift
@MainActor public var title: String? { get set } -
The key name of the cell
Declaration
Swift
@MainActor public var keyName: String? { get set } -
The value of the cell, indicating the index of the selected item.
The default value is
-1, indicating an empty selection.Declaration
Swift
@MainActor public var value: Int { get set } -
This property indicates whether an empty selection is allowed.
Declaration
Swift
@MainActor public var allowsEmptySelection: Bool { get set } -
The width of the segment in the control. The default width is 73. Setting this property has no effect if
apportionsSegmentWidthsByContentistrue.Declaration
Swift
@MainActor public var segmentWidth: CGFloat { get set } -
The height of the segment in the control. If
segmentHeightis nil, use the AutoLayout system height of the first segment as the unique height for all segments.Declaration
Swift
@MainActor public var segmentHeight: CGFloat? { get set } -
Implementation of the change handler. This is invoked on changes to the
valueproperty.Declaration
Swift
@MainActor open var onChangeHandler: ((Int) -> Void)? { get set } -
The array of the valid options. The maximum number of items in the array is limited to 5. If there are more than 5 items, only the first 5 items will be used.
Declaration
Swift
@MainActor public var valueOptions: [String] { get set } -
Indicates whether the user can change the selection or not. This is set to
trueby default.Declaration
Swift
@MainActor public var isEditable: Bool { get set } -
isEnabledandisEditableare in sync.Declaration
Swift
@MainActor public override var isEnabled: Bool { get set } -
This property specifies whether the segmented control is always below the
keyNameor not.The default is
false, meaning that the segmented control will be displayed in the same line askeyNameif the width of the segmented control can fit.Declaration
Swift
@MainActor open var forcesStackedLayout: Bool { get set } -
Indicates whether the control attempts to adjust segment widths based on their content widths. The default is
false.Declaration
Swift
@MainActor public var apportionsSegmentWidthsByContent: Bool { get set } -
The type of the value.
Declaration
Swift
public typealias ValueType = Int -
Sets the button attributes for the specified control state.
This is used to customize the style of the buttons. If this is not set, the default Fiori style attributes will be used.
Declaration
Swift
@MainActor public func setButtonAttributes(_ buttonAttributes: FUISegmentedControlButtonAttributes, for state: FUIControlState) -
:nodoc
Declaration
Swift
@MainActor open override func prepareForReuse()