iPhone如何使uitableviewcellaccessorydisclosureindicator的背景透明?

4
3个回答

5

刚刚找到了答案。原来只需要3行代码,还要定义一个透明背景的披露指示符.png图片:

UITableViewCell *bgView = [[UITableViewCell alloc] initWithFrame:CGRectZero];
    bgView.backgroundColor=indexPath.row % 2? [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1]: [UIColor whiteColor];
    bgView.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"disclosure.png"]];
    cell.backgroundView=bgView; 


    return cell;

4
在您的 UITableView 的委托中,重写委托方法 tableView:willDisplayCell:forRowAtIndexPath:。在这里,将单元格的 backgroundColor 属性设置为任何颜色,附属视图的背景颜色应匹配。

这个很好用,比上面的答案*干净多了,因为它使用默认图像,所以当苹果更新操作系统时会自动更新。 - Dad
我尝试过这个解决方案,但是我无法让披露后面的区域与我的背景颜色匹配。有什么想法吗? - prostock
我同意 - 这比使用自定义图标来获得透明颜色要好得多。这甚至在 monotouch 中也可以工作 ;) - slott

3
更多详细信息请查看anshuchimala的回答:
cell.contentView.backgroundColor=[UIColor grayColor];//or any color
cell.backgroundColor=[UIColor grayColor];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
cell.accessoryView.backgroundColor=[UIColor clearColor];

2
我正在设置cell.contentView的背景颜色,但奇怪的是accessoryView没有相同的背景颜色。你的帖子让我意识到我应该只设置cell.backgroundColour。谢谢。 - braden

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