我想获取分组表格 View 的所有 View 以更改标签颜色并设置背景颜色。
最佳答案
我找到了答案,无法获取 TableView 部分的标题 View 。但是您可以实现委托(delegate) tableView:viewForHeaderInSection:
来重新创建标题 View 和标签。以下代码将为您提供相同的标题 View 和确切的标签。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
return nil;
}
// Create label with section title
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20.0f, 5.5f, 300.0f, 30.0f)];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:16.5];
label.shadowColor = [UIColor whiteColor];
label.shadowOffset = CGSizeMake(0.0, 1.0);
label.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
label.text = sectionTitle;
// Create header view and add label as a subview
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 44.0f)];
view.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
[view addSubview:label];
return view;
}
关于ios - 如何获取分组 TableView 的标题 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10773703/