public
Last active

An iPhone (Cocoa) segment control that acts like a single toggle button.

  • Download Gist
AKSingleSegmentedControl.h
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// AKSingleSegmentedControl.h
// By Henrik Nyh <http://henrik.nyh.se> 2010-05-14 under the MIT license.
// http://gist.github.com/401670
//
// A segment control that acts like a single toggle button.
 
#import <UIKit/UIKit.h>
 
@interface AKSingleSegmentedControl : UISegmentedControl {
}
 
- (id)initWithItem:(id)item;
 
@end
AKSingleSegmentedControl.m
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#import "AKSingleSegmentedControl.h"
 
@implementation AKSingleSegmentedControl
 
- (id)initWithItem:(id)item {
NSArray *a = [NSArray arrayWithObject:item];
return [super initWithItems:a];
}
 
- (void)setSelectedSegmentIndex:(NSInteger)toValue {
NSInteger newValue = self.selectedSegmentIndex==0 ? -1 : 0;
[super setSelectedSegmentIndex:newValue];
}
 
@end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.