页脚视图的颜色总是比UITableView分隔符的颜色更暗。

7
在我的UITableView中,我像这样设置了分隔符颜色:
- (void)viewDidLoad {
  ...
  self.tableView.separatorColor = [UIColor lightGrayColor];
  ...
}

我将页脚的颜色设置为了这样:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {

  UITableViewHeaderFooterView *footerView = [[UITableViewHeaderFooterView alloc]
                                             initWithFrame:(CGRect){0, 0, 320, 1}];
  footerView.contentView.backgroundColor = [UIColor lightGrayColor];

  return footerView;
}

然而,页脚视图的颜色总是比分隔线的颜色更暗,就像这样:

enter image description here

我该如何使它们具有完全相同的颜色?谢谢。


这与 footerView 的分隔线颜色比表格的分隔线颜色更深无关。事实上,表格的分隔线比 footerView 的分隔线颜色更浅。说实话,你的 footer 分隔线确实是 lightGrayColor,但是单元格分隔线的颜色介于“ccc”或“ddd”之间... - Pham Hoan
@PhamHoan 但是我在viewDidLoad中明确地将分隔符的颜色设置为浅灰色。 - Impossibility
2个回答

28

iOS 6.0及其以上版本,您可以使用下面所提到的UITableView的委托方法来更改页脚视图的背景颜色-

- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section 
{
    //Set the background color of the View
    view.tintColor = [UIColor blueColor];
}

谢谢,但是底部仍然比较暗。 - Impossibility
这实际上是有效的,问题是由于视网膜显示器(显然),页脚比1像素更厚,因此它看起来更暗。谢谢! - Impossibility

0

以上方法都对我无效。唯一有效的方法是从这个帖子中找到的解决方案:

表格区域标题上方的白色分隔符

基本上,您需要手动添加页脚分隔符,使其在自定义页脚视图的上方 1 像素。

-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UITableViewHeaderFooterView *versionView = [[UITableViewHeaderFooterView alloc] initWithFrame:CGRectMake(0, 0, maxScreenWidth, 50)];
    UIView *footerSeparator = [[UIView alloc] initWithFrame:CGRectMake(0, -1, maxScreenWidth, 1)];

    versionView.backgroundColor = [UIColor blackColor];
    footerSeparator.backgroundColor = [UIColor darkGrayColor];//Your color

    [versionView addSubview:footerSeparator];
    return versionView;
}

我唯一遇到的问题是,如果您在表视图中滚动离开页脚分隔符,然后再次滚回来,它似乎会消失。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接