我有UITableView
个static
个单元格,使用storyboards
创建了两个部分。我使用以下代码更改部分headers
的外观。
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
return nil;
}
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(20, 1, 320, 20);
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor lightGrayColor];
label.shadowColor = [UIColor grayColor];
label.shadowOffset = CGSizeMake(-1.0, 1.0);
label.font = [UIFont boldSystemFontOfSize:10];
label.text = sectionTitle;
UIView *view = [[UIView alloc] init];
[view addSubview:label];
return view;
}
它看起来像我想要的方式,但滚动tableView
时,第一个标题中的label
不会使用UIView
滚动。它停留在屏幕中间。至于第二个标题中的label
,它的行为就像它应该的那样。
答案 0 :(得分:0)
如果您还没有实现 tableView:heightForHeaderInSection:,根据Apple文档,它是必需的:
返回的对象可以是UILabel或UIImageView对象,也可以是自定义视图。只有在实现tableView:heightForHeaderInSection:时,此方法才能正常工作。
这可能会导致部分问题。
答案 1 :(得分:0)
我刚刚遇到这个问题并发现我的问题是有一个标题视图,背景颜色设置为clearColor。使用其他任何东西,标题都正确粘贴。