UnderlineSegmentedControl - admiral-team/admiralui-ios GitHub Wiki

Class

A horizontal control with scroll that consists of multiple segments, each segment functioning as a discrete text button. It contains line bottom of selected segment.


Declaration

public class UnderlineSegmentedControl: BaseUnderlineSegmentedControl, AnyAppThemable

Overview

A scrollable horizontal segmented control is a linear set of two or more segments, each of which functions as a button. Use a segmented control to provide closely related choices that affect an object, state, or view. For example, a segmented control can help people switch between views in a toolbar. Avoid using a segmented control to enable actions, such as adding, removing, or editing content. Also you can set that segmented control will not scrollable and can expand over its entire width.

Live example

Configure a Underline Segmented Control

Configuration a Underline Segmented Control the similar UISegmentedControl, but for useful we added constructor with titles.

let segmentControl = UnderlineSegmentedControl(items: ["One", "Two"])
segmentControl.selectedSegmentIndex = 0

If you want to set the indent from the edge, you may use property contentInset.

segmentControl.contentInset = UIEdgeInsets(
    top: 0.0,
    left: 16.0,
    bottom: 0.0,
    right: 16.0)

You can set that segmented control will not scrollable and can expand over its entire width.

segmentControl.isStaticTabs = true

Handle a selection

You register the target-action methods for a segmented control using the valueChanged.

segmentControl.addTarget(self, action: #selector(segmentedValueChanged), for: .valueChanged)

Contribution

You can help us to find bugs or ask us to add features.

  • To start issue please use ready-made templates.
  • To make changes to the repository, you need to create a fork of the project, make changes to the code and create a pull request in our project. You can read more about this in the Github documentation.