FUISegmentedControlFormCell
@IBDesignable
open class FUISegmentedControlFormCell : FUIInlineValidationTableViewCell, FUIPropertyFormCell
A UITableViewCell
subclass, which 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.
Specifying the height for segments by setting segmentHeight
api. By default it is set to nil which means segment will adjust its height to fit content.
Color setting:
Setting text color of buttons in the cell for a state using setTintColor(_:for:) api. Currently disabled
, normal
and selected
are supported.
cell.setTintColor(UIColor.red, for: .selected)
Code usage:
// Optionally, create an array of value option to localized string mappings
let buttonTitles: [[String: String]] = [["LO": "Low"], ["MED": "Medium"], ["HI": "High"]]
// Register FUISegmentedControlFormCell in viewDidLoad() method in the controller.
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.register(FUISegmentedControlFormCell.self, forCellReuseIdentifier: FUISegmentedControlFormCell.reuseIdentifier)
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: FUISegmentedControlFormCell.reuseIdentifier, for: indexPath) as! FUISegmentedControlFormCell
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
fdlFUISegmentedControlFormCell
fdlFUISegmentedControlFormCell_keyLabel
-
The default cell reuse identifier.
Declaration
Swift
open class var reuseIdentifier: String { get }
-
The key name of the cell
Declaration
Swift
@IBInspectable public var keyName: String? { get set }
-
The type of the value
Declaration
Swift
public typealias ValueType = Int
-
The value of the cell
Declaration
Swift
public var value: Int { get set }
-
The width of segment in the control. Default is 73. Setting this property has no effect if
apportionsSegmentWidthsByContent
is true.Declaration
Swift
public var segmentWidth: CGFloat { get set }
-
The height of segment in the control. If segmentHeight is nil, use the AutoLayout system height of the first segment as the unique height for all segments.
Declaration
Swift
public var segmentHeight: CGFloat? { get set }
-
Implementation of change handler. Is invoked on changes to the
value
property.Declaration
Swift
open var onChangeHandler: ((Int) -> Void)?
-
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
@objc public var valueOptions: [String] { get set }
-
Indicates whether the user can change the selection or not. It is set to true by default.
Declaration
Swift
public var isEditable: Bool { get set }
-
isEnabled
andisEditable
are in sync.Declaration
Swift
override public var isEnabled: Bool { get set }
-
Indicates whether the control attempts to adjust segment widths based on their content widths. Default is false.
Declaration
Swift
public var apportionsSegmentWidthsByContent: Bool { get set }
-
The key name label in the cell
Declaration
Swift
@IBOutlet public private(set) weak var keyLabel: UILabel!
-
Undocumented
Declaration
Swift
open override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?)
-
Declaration
Swift
open override func applyTintColor(forState state: UIControlState)