FUIDimensionSelector

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

    public var titles: [String]! { get set }
  • Content inset for the dimension selector. Currently support leading and trailing insets.

    Declaration

    Swift

    public var contentInset: NSDirectionalEdgeInsets { get set }
  • Callback for selection changes

    Code usage:

    dimensionSelector.selectionDidChangeHandler = { [weak self] index in
    print("selected: \(index ?? -1)")
    }
    

    Declaration

    Swift

    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 FUIDimensionSelector will 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

    public var selectedIndex: Int? { get set }
  • Custom title insets for each segment.

    Declaration

    Swift

    public var titleInsets: NSDirectionalEdgeInsets { get set }
  • The space between two segments. The default value is 6.

    Declaration

    Swift

    public var interItemSpacing: CGFloat { get set }
  • If set to false, the previous selection will be removed.

    Declaration

    Swift

    public var isEnable: Bool { get set }
  • Segment width for FUIDimensionSelector. The default is .intrinsic

    Declaration

    Swift

    public var segmentWidthMode: FUISegmentWidthMode { get set }
  • A Boolean value indicates whether empty selection is allowed. Default to true.

    Declaration

    Swift

    public var allowEmptySelection: Bool { get set }
  • Initializes and returns a dimension selector with segments having the given titles.

    Declaration

    Swift

    public init(titles: [String], selectedIndex: Int? = nil)

    Parameters

    titles

    An array of String objects (for segment titles).

    selectedIndex

    An integer for setting preselection.

    Return Value

    A FUIDimensionSelector object or nil if there was a problem in initializing the object.

  • Returns the number of segments the dimension selector has.

    Declaration

    Swift

    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

    open func titleForSegment(at index: Int) -> String?

    Parameters

    index

    An 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

    open func setTitle(_ withTitle: String, forSegementAt index: Int)

    Parameters

    withTitle

    A string to display in the segment as its title.

    index

    An 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

    open func insertSegment(_ withTitle: String, at index: Int)

    Parameters

    withTitle

    A string to display in the segment as its title.

    index

    An 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.

    animated

    To 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

    open func removeSegment(at index: Int)

    Parameters

    index

    An 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

    open func removeAllSegments()