How to customize the UISegmentedControl in iOS?
I am customizing the U开发者_高级运维ISegmentedControl, but I got a problem.
How to apply background image in the UISegmentedControl ? Changing the tint color does not fulfill my requirements.
Thanks
////Segmented Controll
NSArray *segmentTextContent = [NSArray arrayWithObjects: @"First",@"Second",@"Third",@"Forth", nil];
segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
segmentedControl.frame = CGRectMake(2, 5, 316, 35);
[segmentedControl addTarget:self action:@selector(segmentAction) forControlEvents:UIControlEventValueChanged];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.enabled = true;
segmentedControl.selectedSegmentIndex = 0;
// cutomize the font size inside segmentedControl
for (id segment in [segmentedControl subviews])
{
for (id label in [segment subviews])
{
if ([label isKindOfClass:[UILabel class]])
{
[label setTextAlignment:UITextAlignmentCenter];
[label setFont:[UIFont boldSystemFontOfSize:11]];
//[label setTextColor:[UIColor greenColor]];
}
}
}
You could try http://idevrecipes.com/2010/12/11/custom-segmented-controls/.
精彩评论