Skip to content
This repository has been archived by the owner on Nov 11, 2019. It is now read-only.

A swift representation of yonat/MultiSelectSegmentedControl

License

Notifications You must be signed in to change notification settings

MihaelIsaev/MultiSelectSegmentedControl

Repository files navigation

Release version

Deprecated

Take a look at my new awesome UIKitPlus lib which will give you an ability to build this kind of control in a minute.

Swift 3.0.1

MultiSelectSegmentedControl

multiple selection segmented control rewritten from yonat Obj-C lib

Example

A subclass of UISegmentedControl that supports selection multiple segments.

No need for images - works with the builtin styles of UISegmentedControl.

Installation

Simply Copy and Paste MultiSelectSegmentedControl.swift file in your Xcode Project :)

Usage

Drag a UISegmentedControl into your view in Interface Builder.

Set its class to MultiSelectSegmentedControl.

Set an outlet for it, perhaps calling it something creative such as myMultiSeg.

Set the selected segments:

//to select 1 and 2 segments
myMultiSeg.selectedSegmentIndexes = IndexSet(integersIn: 1...2)
//to select 4 segment in addition to 1 and 2
myMultiSeg.selectedSegmentIndexes.insert(4)
//to select just 2 segment
myMultiSeg.selectedSegmentIndexes = IndexSet(integer: 2)

Get the selected segment indices:

let selectedIndices: IndexSet = myMultiSeg.selectedSegmentIndexes

Get the selected segment titles:

print("These items are selected: \(myMultiSeg.selectedSegmentTitles)")

If you want to be notified of changes to the control's value, make sure your ViewController conforms to the delegate protocol

class YourAwesomeViewController: UIViewController, MultiSelectSegmentedControlDelegate {

...and set the delegate, perhaps in your viewDidLoad method:

myMultiSeg.delegate = self

You are notified of changes through the following method:

func multiSelect(multiSelectSegmendedControl: MultiSelectSegmentedControl, didChangeValue value: Bool, atIndex index: Int) {
    print("multiSelect delegate selected: \(value) atIndex: \(index)")
}

About

A swift representation of yonat/MultiSelectSegmentedControl

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages