#import
@interface UIMultipleSelectionSegmentControl : UISegmentedControl {
NSMutableSet *indices ;
}
@property( nonatomic,retain) NSMutableSet *indices ;
@end
#import "UIMultipleSelectionSegmentControl.h"
@implementation UIMultipleSelectionSegmentControl
@synthesize indices ;
- (NSSet *) selectedSegmentIndices
{
return self.indices ;
}
- (void) setSelectedSegmentIndices: (NSSet *) aSet
{
NSEnumerator *enumerator = [aSet objectEnumerator];
NSNumber *value;
while ((value = [enumerator nextObject]))
{
[self setSelectedSegmentIndex: [value integerValue]] ;
}
}
- (void) setSelectedSegmentIndex: (NSInteger) anIndex
{
if ( self.indices == nil ) self.indices = [NSMutableSet set] ;
if ( anIndex >= 0 )
{
NSNumber *indexNumber ;
UIImage *myImage ;
indexNumber = [NSNumber numberWithInt: anIndex] ;
if ( ! [self.indices containsObject: indexNumber] )
{
[self.indices addObject: indexNumber] ;
switch( anIndex )
{
case 0 :myImage = [UIImage imageNamed: @"segment-5-sel.png"] ; break ;
case 1 :myImage = [UIImage imageNamed: @"segment-10-sel.png"] ; break ;
case 2 :myImage = [UIImage imageNamed: @"segment-20-sel.png"] ; break ;
case 3 :myImage = [UIImage imageNamed: @"segment-50-sel.png"] ; break ;
case 4 :myImage = [UIImage imageNamed: @"segment-100-sel.png"] ; break ;
case 5: myImage = [UIImage imageNamed: @"segment-200-sel.png"] ; break ;
}
[super setSelectedSegmentIndex: anIndex] ;
}
else
{
[self.indices removeObject: indexNumber] ;
[super setSelectedSegmentIndex: -indexNumber] ;
switch( anIndex )
{
case 0 :myImage = [UIImage imageNamed: @"segment-5.png"] ; break ;
case 1 :myImage = [UIImage imageNamed: @"segment-10.png"] ; break ;
case 2 :myImage = [UIImage imageNamed: @"segment-20.png"] ; break ;
case 3 :myImage = [UIImage imageNamed: @"segment-50.png"] ; break ;
case 4 :myImage = [UIImage imageNamed: @"segment-100.png"] ; break ;
case 5: myImage = [UIImage imageNamed: @"segment-200.png"] ; break ;
}
}
[self setImage: myImage forSegmentAtIndex: anIndex] ;
}
}
- (void)dealloc {
[indices release] ;
[super dealloc];
}
@end