Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone: UISegmentedControl with custom images on pressed state

I am using a UISegmentedControl with some custom images:

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:nil];
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"0.png"] atIndex:0 animated:NO];
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"1.png"] atIndex:1 animated:NO];
[segmentedControl insertSegmentWithImage:[UIImage imageNamed:@"2.png"] atIndex:2 animated:NO];
segmentedControl.frame = CGRectMake(0, 0, 90, 30);
[self.view addSubview:segmentedControl];
[segmentedControl release];

This part works fine. But, it still uses Apple's styling for the control and just adds my images over it. Is there a way that I don't have to use Apple's styles, and customize the conrol with my own images with no background? I would also like to have my own "selected" state images.

Possible?

like image 461
Nic Hubbard Avatar asked Oct 25 '22 07:10

Nic Hubbard


1 Answers

Nic,

After playing with this for a while, I decided to simply "roll my own" in a way.

I made some button images in photoshop and got everything looking like a segmented control. Then, I set a different image for the "selected" states of all the buttons. When one button was pressed, I called setSelected:NO to the others. Then, I handled whatever I needed to do.

I'd love to hear other solutions.

like image 78
DexterW Avatar answered Nov 15 '22 08:11

DexterW