#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
Oh man, this sounds a little hacky. Do you find using a table view that much more effort?
ReplyDeleteYes you do need stuff this when you have a question like click all that applies without requiring a navigation
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteHey... I did exactly as you said and implemented the segementedcontrol like this:
ReplyDeleteJHMultipleSegmentedControl *segDia = [[JHMultipleSegmentedControl alloc] initWithFrame:CGRectMake(20, 160, 270, 30)];
[segDia setSelectedSegmentIndex:-1];
[segDia insertSegmentWithImage:[UIImage imageNamed: @"domingo.png"] atIndex:0 animated:YES];
[segDia insertSegmentWithImage:[UIImage imageNamed: @"segunda.png"] atIndex:1 animated:YES];
[segDia insertSegmentWithImage:[UIImage imageNamed: @"terca.png"] atIndex:2 animated:YES];
[segDia insertSegmentWithImage:[UIImage imageNamed: @"quarta.png"] atIndex:3 animated:YES];
[segDia insertSegmentWithImage:[UIImage imageNamed: @"quinta.png"] atIndex:4 animated:YES];
[segDia insertSegmentWithImage:[UIImage imageNamed: @"sexta.png"] atIndex:5 animated:YES];
[segDia insertSegmentWithImage:[UIImage imageNamed: @"sabado.png"] atIndex:6 animated:YES];
[self.view addSubview:segDia];
But it looks like there is another segmentedcontrole behinded, blue.
Any ideias/!