FUIDimensionSelector
@MainActor
open class FUIDimensionSelector : UIView
A FUIDimensionSelector object is a horizontal control made up of multiple segments, each segment functioning as a discrete button. Selection is mutually exclusive.
Code usage:
let dimensionSelector = FUIDimensionSelector(titles: titles)
dimensionSelector.selectedIndex = 1
dimensionSelector.interItemSpacing = 20
dimensionSelector.selectionDidChangeHandler = { [weak self] index in
print("selected: \(index ?? -1)")
}
Styling
Attribute setting:
Setting the items’ styling for title and border with setAttribute(attribute, for:). Currently .normal, .selected and .disabled are supported.
let attribute = FUISegmentAttribute(textColor: .red, borderColor: .blue)
dimensionSelector.setAttribute(attribute: attribute, for: .selected)
Theming
fdlFUIDimensionSelector {
title-color: green;
title-color-selected: red;
title-color-disabled: gray;
border-color: blue;
border-color-selected: orange;
border-color-disabled: gray;
interItem-spacing: 20;
title-inset: 5 10 5 10;
content-inset: 0 40 0 40;
}
-
Titles for the segments
Declaration
Swift
@MainActor public var titles: [String]! { get set } -
Content inset for the dimension selector. Currently support leading and trailing insets.
Declaration
Swift
@MainActor public var contentInset: NSDirectionalEdgeInsets { get set } -
Callback for selection changes
Code usage:
dimensionSelector.selectionDidChangeHandler = { [weak self] index in print("selected: \(index ?? -1)") }Declaration
Swift
@MainActor public var selectionDidChangeHandler: ((Int?) -> Void)? -
The index number identifying the selected segment (that is, the last segment touched).
When this property is directly set to a new value, the event handler registered on
FUIDimensionSelectorwill get invoked. If this property is set to a negative value, the current selection will be canceled. If the value exceeds the upper range, no change is made to the current selection. If the value is set to nil, it will deselect the current selection.Declaration
Swift
@MainActor public var selectedIndex: Int? { get set } -
Custom title insets for each segment.
Declaration
Swift
@MainActor public var titleInsets: NSDirectionalEdgeInsets { get set } -
The space between two segments. The default value is 6.
Declaration
Swift
@MainActor public var interItemSpacing: CGFloat { get set } -
If set to false, the previous selection will be removed.
Declaration
Swift
@MainActor public var isEnable: Bool { get set } -
Segment width for
FUIDimensionSelector. The default is.intrinsicDeclaration
Swift
@MainActor public var segmentWidthMode: FUISegmentWidthMode { get set } -
A Boolean value indicates whether empty selection is allowed. Default to
true.Declaration
Swift
@MainActor public var allowEmptySelection: Bool { get set } -
Initializes and returns a dimension selector with segments having the given titles.
Declaration
Swift
@MainActor public init(titles: [String], selectedIndex: Int? = nil)Parameters
titlesAn array of String objects (for segment titles).
selectedIndexAn integer for setting preselection.
Return Value
A
FUIDimensionSelectorobject or nil if there was a problem in initializing the object.
-
Returns the number of segments the dimension selector has.
Declaration
Swift
@MainActor open var numberOfSegments: Int { get } -
Get title for a segment in the dimension selector.
Code usage:
let titles = ["button0", "button1", "button2"] let dimensionSelector = FUIDimensionSelector(titles: titles) dimensionSelector.titleForSegment(at: 1)Declaration
Swift
@MainActor open func titleForSegment(at index: Int) -> String?Parameters
indexAn index number identifying a segment in the control. It must be a number between 0 and the number of segments (numberOfSegments) minus 1; values exceeding this upper range are pinned to it.
Return Value
Returns the string (title) assigned to the receiver as content. If exceeding this lower or upper range, will return nil.
-
Set title for a segment in dimension selector.
Code usage:
let titles = ["button0", "button1", "button2"] let dimensionSelector = FUIDimensionSelector(titles: titles) dimensionSelector.setTitle("change title for button1", forSegmentAt: 1)Declaration
Swift
@MainActor open func setTitle(_ withTitle: String, forSegementAt index: Int)Parameters
withTitleA string to display in the segment as its title.
indexAn index number identifying a segment in the control. It must be a number between 0 and the number of segments (numberOfSegments) minus 1; values exceeding this upper range are pinned to it.
-
Inserts a segment at a specific position in the dimension selector and gives it a title as content.
Code usage:
let titles = ["button0", "button1", "button2"] let dimensionSelector = FUIDimensionSelector(titles: titles) dimensionSelector.insertSegment("new title", at: 1)Declaration
Swift
@MainActor open func insertSegment(_ withTitle: String, at index: Int)Parameters
withTitleA string to display in the segment as its title.
indexAn index number identifying a segment in the control. It must be a number between 0 and the number of segments (numberOfSegments); values exceeding this upper range are pinned to it.
animatedTo be implemented.
-
Removes the specified segment from the dimension selector.
Code usage:
let titles = ["button0", "button1", "button2"] let dimensionSelector = FUIDimensionSelector(titles: titles) dimensionSelector.removeSegment(at: 1)Declaration
Swift
@MainActor open func removeSegment(at index: Int)Parameters
indexAn index number identifying a segment in the control. It must be a number between 0 and the number of segments (numberOfSegments) minus 1; values exceeding this upper range are pinned to it.
-
Removes all segments of the dimension selector.
Declaration
Swift
@MainActor open func removeAllSegments()
-
Public setter to set attributes for segments with different control states.
Code usage:
let attribute = FUISegmentAttribute(textColor: .red, borderColor: .blue) dimensionSelector.setAttribute(attribute: attribute, for: .selected)Declaration
Swift
@MainActor open func setAttribute(attribute: FUISegmentAttributes, for state: FUIControlState)Parameters
attributeFUISegmentAttributesfor setting customized attributes.stateFUIControlStateCurrently support.normal,.selectedand.disabled. -
Public getter to read attribute for segments.
Declaration
Swift
@MainActor open func getAttribute(for state: FUIControlState) -> FUISegmentAttributesParameters
statestatefor whichFUISegmentAttributesis needed.Return Value
current
FUISegmentAttributesfor the styling. -
An enum for setting the segment mode in
See moreFUIDimensionSelectorDeclaration
Swift
@frozen public enum FUISegmentWidthMode