【问题标题】:Customizing UITableViewCell IOS自定义 UITableViewCell IOS
【发布时间】:2012-10-05 15:19:03
【问题描述】:

目前我的单元格是这样的:http://tinypic.com/view.php?pic=344uz2a&s=6

可以看出,由于某种原因,它拒绝用 backgroundColor 白色填充单元格的右侧部分。而且我不知道问题的原因或可能是什么?

这就是我实现 TableView / Cells 的方式。在 viewDidLoad 我将整个 tableView 设置为 clearColor 以隐藏“emptyCells”。

- (void)viewDidLoad{

 self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
 tableView.backgroundColor = [UIColor clearColor];
}

在下面的方法中,我尝试设置单元格背景颜色。不幸的是,如上所述,它拒绝在单元格中将 whiteColor 设置为右侧。

- (UITableViewCell *)tableView:(UITableView *)pTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"SearchCell";
UITableViewCell *cell = [pTableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellIdentifier];
}
Task *task = [self.searchResults objectAtIndex:indexPath.row];

UILabel *nameLabel = (UILabel *)[cell viewWithTag:1];
UILabel *bookLabel = (UILabel *)[cell viewWithTag:2];
UILabel *chapterLabel = (UILabel *)[cell viewWithTag:3];

[nameLabel setText:task.name];
[bookLabel setText:task.book.name];
[chapterLabel setText:task.chapter.name];

cell.backgroundColor =  [UIColor whiteColor];
cell.contentView.backgroundColor =  [UIColor whiteColor];
cell.backgroundView.backgroundColor = [UIColor whiteColor];

return cell;
}

有什么想法吗?我错过了什么或者我能做些什么来解决这个“颜色”问题?谢谢

【问题讨论】:

    标签: ios uitableview background-color


    【解决方案1】:

    看起来你需要像这样设置附件视图的背景颜色:

    self.accessoryView.backgroundColor = [UIColor whiteColor];
    

    如果您查看背景视图的边界,它可能不会跨越整个表格单元格。

    【讨论】:

      【解决方案2】:

      试试

      cell.backgroundView.backgroundColor = [UIColor whiteColor];
      

      cell.backgroundView.layer.backgroundColor = [UIColor whiteColor].CGColor;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-04-12
        • 2017-02-08
        • 1970-01-01
        • 2012-01-09
        • 2014-07-28
        • 1970-01-01
        • 2015-11-13
        相关资源
        最近更新 更多