Skip to content

dancarvajc/CustomSegmentedControl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CustomSegmentedControl

An simple example of a custom segmented control for UIKit.

RocketSim_Screenshot_iPhone_14_Pro_2023-02-10_14.35.05RocketSim_Screenshot_iPhone_14_Pro_2023-02-10_14.36.08

Use

Declares the titles for each segment in an array.

private let buttonTitles: [String] = ["Button 1", "Button 2", "Button 3"]

Then create an instance of the custom segmented control passing it the array as argument:

private lazy var segmentedControl: CustomSegmetedControl = CustomSegmetedControl(buttonTitles: buttonTitles)

Finally, conforms to the delegate protocol to know which button was pressed.

extension ViewController: CustomSegmetedControlDelegate {
    func buttonPressed(buttonTitlesIndex: Int, title: String?) {
	// some action
    }
}

Video

segmentedControlDemo.mp4

About

Simple custom segmented control for UIKit (iOS)

Topics

Resources

Stars

Watchers

Forks

Languages