【问题标题】:Footer view's color always darker than UITableView separator's color页脚视图的颜色总是比 UITableView 分隔符的颜色深
【发布时间】:2015-04-08 05:35:32
【问题描述】:

在我的 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;
}

但是,页脚视图的颜色总是比分隔符的颜色深,如下所示:

如何让它们的颜色完全相同?谢谢。

【问题讨论】:

  • 不是 footerView 分隔符比表格分隔符暗。它的 table 分隔符比 footerView 轻。 TBH,您的页脚分隔符为 lightGrayColor,但单元格分隔符介于“ccc”或“ddd”之间...
  • @PhamHoan 但是我在 viewDidLoad 中明确地将分隔符的颜色设置为浅灰色。

标签: ios objective-c uitableview


【解决方案1】:

从 iOS 6.0 开始,您可以使用下面提到的UITableView's 委托方法来更改页脚视图背景的颜色-

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

【讨论】:

  • 谢谢,但不幸的是,页脚仍然较暗。
  • 这确实有效,问题是由于视网膜显示(显然),页脚比 1 px 厚,所以它看起来很暗。谢谢!
【解决方案2】:

以上都不适合我。唯一有效的是这个线程的解决方案:

White Separator Above Table Section Headers

基本上,您需要在自定义页脚视图上方 1 px 处手动添加页脚分隔符。

-(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;
}

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-06
    • 2016-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多