我使用以下代码设置 uitableview 部分的标题视图。问题是,在我滚动表格视图之前,背景颜色(mainLightColor_2)不会出现。如何在加载时显示背景颜色?
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 24)];
headerView.backgroundColor = [Utility mainLightColor_2]; //mainLightColor is a blue color
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 2, 200, 20)];
label.backgroundColor = [UIColor clearColor];
label.textColor = [Utility mainDarkColor];
label.text = @"Past Activities";
[headerView addSubview:label];
return headerView;
}
滚动前:
滚动后: