Multiple selection segmented control.
A subclass of UISegmentedControl that supports selecting multiple segments.
No need for images - works with the builtin styles of UISegmentedControl.
- Standard iOS look and feel.
- Use from either storyboard or code.
- iOS 8.0+
- Xcode 7.3
You can use CocoaPods to install YourLibrary by adding it to your Podfile:
platform :ios, '8.0'
use_frameworks!
pod 'MultiSelectSegmentedControl'To get the full benefits import YourLibrary wherever you import UIKit
import UIKit
import MultiSelectSegmentedControlIn Interface Builder:
- Drag a
UISegmentedControlinto your storyboard. - Set its class to
MultiSelectSegmentedControl. - Set an outlet for it, e.g.,
myMultiSeg.
In code:
self.myMultiSeg = [[MultiSelectSegmentedControl alloc] init];myMultiSeg.selectedSegmentIndexes = [NSIndexSet indexSetWithIndex:1];NSIndexSet *selectedIndices = myMultiSeg.selectedSegmentIndexes;Or to get the titles:
NSArray *titles = myMultiSeg.selectedSegmentTitles;To be notified of changes to the control's value, make sure your ViewController conforms to the delegate protocol:
@interface MyViewController : UIViewController <MultiSelectSegmentedControlDelegate>...and set the delegate, perhaps in your viewDidLoad method:
myMultiSeg.delegate = self;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);
}
}