views:

1529

answers:

3

Does anybody know of a way to customize the appearance of the string based UISegmentedControl? I am trying to set the background color of the cell and the text color differently depending on the selected state of the item.

Alternatively, do you know of a way to create UIImages on the fly in which to include custom strings? (e.g. create uiimage with white background, overlay text, add to segmented control).

I know that you can only have strings or images in the segmented control...

Cheers!

+1  A: 

UISegmentedControl has a tintColor property -- this allows you to change what color the control is, but not the general "style" (the rounded, beveled shape):

segmentedControl.tintColor = [UIColor blueColor];

As for creating UIImages on the fly, you can create a CGContext, do whatever drawing you need to in that context (including strings), and then get a UIImage out of the context's CGImage:

CGContextRef drawContext = CGBitmapContextCreate(<many parameters>);
//do drawing here
CGImageRef finalImage = CGBitmapContextCreateImage(drawContext);
UIImage *cellImage = [UIImage finalImage];
Arclite
A: 

Check out my blog post showing independently setting the color of each individual segment.

http://www.framewreck.net/2010/07/custom-tintcolor-for-each-segment-of.html

A: 

Can i find here the answer for this: http://stackoverflow.com/questions/3977948/uisegmentedcontrol-gives-different-background-then-single-uibarbuttonitem or is that an other problem with the segmentcontrol?

meersmans