Created
May 14, 2010 21:06
-
-
Save henrik/401670 to your computer and use it in GitHub Desktop.
An iPhone (Cocoa) segment control that acts like a single toggle button.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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