我使用以下代码来设置 uitableview 部分的标题 View 。问题是,在我滚动表格 View 之前,背景颜色 (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;
}
滚动前:
滚动后:
最佳答案
您还应该实现 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
方法。
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 24;
}
关于ios - 直到滚动才显示 uitableview 标题背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16633177/