我在 uitableview 的标题中添加了分段控件。这很好用。但由于某种原因,我无法使分段按钮(或至少只是第一个按钮)具有红色背景色。它只加载默认的银色。
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView* NEWview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
NEWview.backgroundColor = [UIColor colorWithRed:78.0/255.0f green:88.0/255.0f blue:74.0/255.0f alpha:1.0];
NSArray *itemArray = [NSArray arrayWithObjects: @"Organisations", @"Events", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
segmentedControl.frame = CGRectMake(15, 5, 290, 30);
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
segmentedControl.selectedSegmentIndex = 1;
UIColor *newSelectedTintColor = [UIColor redColor];
[[[segmentedControl subviews] objectAtIndex:0] setTintColor:newSelectedTintColor];
[NEWview addSubview:segmentedControl];
return NEWview;
}
有任何想法吗?提前感谢您的帮助..