MultiSelectSegmentedControl

Multiple-Selection UISegmentedControl.

A subclass of UISegmentedControl that supports selecting multiple segments.

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

Features

  • [x] Standard iOS look and feel.
  • [x] Use from either storyboard or code.

Requirements

  • iOS 8.0+
  • Xcode 7.3

Installation

CocoaPods

You can use CocoaPods to install YourLibrary by adding it to your Podfile:

platform :ios, '8.0'
use_frameworks!
pod 'MultiSelectSegmentedControl'
Ruby

To get the full benefits import YourLibrary wherever you import UIKit

import UIKit
import MultiSelectSegmentedControl
Swift

Usage

Creating a MultiSelectSegmentedControl

In Interface Builder:

  1. Drag a UISegmentedControl into your storyboard.
  2. Set its class to MultiSelectSegmentedControl.
  3. Set an outlet for it, e.g., myMultiSeg.

In code:

self.myMultiSeg = [[MultiSelectSegmentedControl alloc] init];
Objc

Setting selected segments

myMultiSeg.selectedSegmentIndexes = [NSIndexSet indexSetWithIndex:1];
Objc

Getting selected segments

NSIndexSet *selectedIndices = myMultiSeg.selectedSegmentIndexes;
Objc

Or to get the titles:

NSArray *titles = myMultiSeg.selectedSegmentTitles;
Objc

Handling user selection changes

To be notified of changes to the control's value, make sure your ViewController conforms to the delegate protocol:

@interface MyViewController : UIViewController <MultiSelectSegmentedControlDelegate>
Objc

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

myMultiSeg.delegate = self;
Objc

Then override the delegate protocol method:

-(void)multiSelect:(MultiSelectSegmentedControl *)multiSelectSegmentedControl didChangeValue:(BOOL)selected atIndex:(NSUInteger)index {
	if (selected) {
		NSLog(@"Selected segment %u", index);
	} else {
		NSLog(@"Deselected segment %u", index);
	}
}
Objc

GitHub