DimensionSelector

public struct DimensionSelector : View

A DimensionSelector object is a horizontal control made of multiple segments, each segment functioning as a discrete button. Selection is mutually exclusive.

## Code usage:

 let titles = ["intraday: 1min", "one day: 1min", "1year:1day", "3years:1week"]
 var dimensionSelector: DimensionSelector!
 var cancellableSet: Set<AnyCancellable> = []

 dimensionSelector = DimensionSelector(segmentTitles: segmentTitltes, selectedIndex: stockModel.indexOfStockSeries)
 dimensionSelector.selectionDidChangePublisher
     .store(in: &cancellableSet)
  • Titles for the segments

    Declaration

    Swift

    public var titles: [String] { get set }
  • A dictionary for setting attributes.

    Declaration

    Swift

    public var segmentAttributes: [ControlState : SegmentAttributes] { get set }
  • Custom title insets for each segment.

    Declaration

    Swift

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

    Declaration

    Swift

    public var interItemSpacing: CGFloat { get set }
  • The index number identifying the selected segment (that is, the last segment touched).

    When this property is directly set to a new value by developer, the event handler registered on DimensionSelector will get invoked. If this property is set to a negative value, the current selection will be canceled. If exceeding the upper range, no change to the current selection. If the value is set to nil, it will de-select the current selection.

    Declaration

    Swift

    public var selectedIndex: Int? { get set }
  • If set to false, previous selection will be removed.

    Declaration

    Swift

    public var isEnable: Bool { get set }
  • Content inset for the segmented control.

    Declaration

    Swift

    public var contentInset: EdgeInsets { get set }
  • Segment width, default is .intrinsic

    Declaration

    Swift

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

    Declaration

    Swift

    public var allowEmptySelection: Bool { get set }
  • A Publisher which signals selection change.

    Declaration

    Swift

    public private(set) lazy var selectionDidChangePublisher: AnyPublisher<Int?, Never> { mutating get set }
  • Initializes and returns a segmented control with segments having the given titles.

    Declaration

    Swift

    public init(segmentTitles: [String],
                interItemSpacing: CGFloat = 6,
                titleInsets: EdgeInsets = EdgeInsets(top: 8, leading: 8, bottom: 8, trailing: 8),
                selectedIndex: Int? = nil,
                contentInset: EdgeInsets? = nil)

    Parameters

    segmentTitles

    An array of String objects (for segment titles).

    interItemSpacing

    Margin between two segments, default is 6.

    titleInsets

    Title insets for each segment.

    selectedIndex

    An integer for setting pre-selection.

    contentInset

    Option, content inset for the segmented control. Currently support leading and trailing insets.

  • Declaration

    Swift

    public var body: some View { get }