2011-08-17 41 views
6

我定製UISegmentedControl,但我有一個問題。如何自定義在iOS中UISegmentedControl?

如何在UISegmentedControl應用背景圖片?更改色調顏色不符合我的要求。

感謝

+0

這裏有幾個很好的替代品:http://www.cocoacontrols.com/search?utf8=%E2%9C%93&q=segmented&commit=Search – Luke

回答

5
////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]]; 
     } 
    }   
}