【发布时间】:2013-05-19 09:24:43
【问题描述】:
我使用以下代码来设置 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;
}
滚动前:
滚动后:
【问题讨论】:
-
尝试设置
label.opaque = NO; -
刚刚尝试了您的代码,它运行良好,可能问题出在 [Utility mainLightColor_2] 方法上,尝试将其替换为 [UIColor blueColor] 只是为了测试,看看会发生什么。
-
你可以尝试发布实用程序类代码吗?
-
@MariamN。那也没用。
-
您在哪个 iOS 版本上进行测试?你在使用故事板吗?
标签: ios uitableview