How can I set the icon image for selected
state of the UISegmentedControl
. Is the UISegmentedControl
really missing this functionality or
Enhancement of @Kuldeep's Answer
you may have two or more controls in segmentcontrol
[_segmentcontrol addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
if you want to replace all images differently than use this code..
-(void)segmentAction:(UISegmentedControl*)sender
{
if(sender.selectedSegmentIndex==0)
{
[sender setImage:[UIImage imageNamed:@"calf_selected.png"] forSegmentAtIndex:sender.selectedSegmentIndex];//0 index
[sender setImage:[UIImage imageNamed:@"wrist.png"] forSegmentAtIndex:1];
}
else
{
[sender setImage:[UIImage imageNamed:@"calf.png"] forSegmentAtIndex:sender.selectedSegmentIndex];//for 1 index
[sender setImage:[UIImage imageNamed:@"wrist_selected.png"] forSegmentAtIndex:0];
}
}