38
You can use the methods which are described in the iOS developer libary:
Scroll down to the "Customizing Appearance" section. There are methods to set background images for several button states, button divider images, etc.
These methods are only available in iOS5 and later.
@property tintColor
– backgroundImageForState:barMetrics:
– setBackgroundImage:forState:barMetrics:
– contentPositionAdjustmentForSegmentType:barMetrics:
– setContentPositionAdjustment:forSegmentType:barMetrics:
– dividerImageForLeftSegmentState:rightSegmentState:barMetrics:
– setDividerImage:forLeftSegmentState:rightSegmentState:barMetrics:
– titleTextAttributesForState:
– setTitleTextAttributes:forState:
I wrote something that works as @rpetrich was explaining without placing in a array and in my opinion is the easiest solution to this. Hope someone finds this useful
.h
IBOutlet UIButton *index0;
IBOutlet UIButton *index1;
IBOutlet UIButton *index2;
IBOutlet UIImageView *segMentControl;
-(IBAction)segmentSwitch:(UIButton *) buttonIndexPressed;
.m
-(IBAction)segmentSwitch:(UIButton *) buttonIndexPressed
{
if (buttonIpressed == index0)
{
[segmentControl setImage:[UIImage imageNamed:@"Seg1Sel.png"]];
NSLog(@"index 0 pushed");
index0.enabled = NO;
index1.enabled = YES;
index2.enabled = YES;
}
else if (buttonIpressed == index1)
{
[segmentControl setImage:[UIImage imageNamed:@"Seg2Sel.png"]];
NSLog(@"index 1 pushed");
index0.enabled = YES;
index1.enabled = NO;
index2.enabled = YES;
}
else if (buttonIpressed == index2)
{
[segmentControl setImage:[UIImage imageNamed:@"Seg3Sel.png"]];
NSLog(@"index 2 pushed");
index0.enabled = YES;
index1.enabled = YES;
index2.enabled = NO;
}
}