Skip to content

Instantly share code, notes, and snippets.

@henrik
Created May 14, 2010 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrik/401670 to your computer and use it in GitHub Desktop.
Save henrik/401670 to your computer and use it in GitHub Desktop.
An iPhone (Cocoa) segment control that acts like a single toggle button.
// 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
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment