我正在使用下面的代码在我的分段控件中设置文本颜色。但是,它似乎不起作用。我在这里错过了什么吗?
// Set up segment control
NSArray *itemArray = [NSArray arrayWithObjects: @"Popular", @"Starred", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
segmentedControl.frame = CGRectMake(40, 200, 220, 20);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.selectedSegmentIndex = 0;
self.navigationItem.titleView = segmentedControl;
for (id segment in [segmentedControl subviews])
{
for (id label in [segment subviews])
{
if ([label isKindOfClass:[UILabel class]])
{
[label setTextAlignment:UITextAlignmentCenter];
[label setColor:[UIColor blackColor]];
}
}
}