How to customize the background/border colors of a grouped table view cell?
阅读这篇文章后,我尝试使用这个解决方案。这是我的代码,在 tableViewDelegate 方法中:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
CustomCellBackgroundView *customBackground = [CustomCellBackgroundView alloc];
[customBackground setBorderColor:[UIColor blackColor]];
[customBackground setFillColor:[UIColor redColor]];
[customBackground setPosition:0]; //i'll deal with that later
[cell setSelectedBackgroundView:customBackground];
[customBackground release];
UIImageView* selectedBackgroundCell = [[[UIImageView alloc] initWithFrame:CGRectNull] autorelease];
[selectedBackgroundCell setImage:[UIImage imageNamed:@"cell_bg_50_hover.png"]];
[customBackground drawRect:selectedBackgroundCell.frame];
[cell setSelectedBackgroundView:selectedBackgroundCell];
//standard background color
[cell setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_bg_50.png"]]];
}
但不幸的是,它并没有改变任何东西。你知道我做错了什么吗?
最佳答案
我相信无论何时制作 View ,您都应该为此指定一些框架。 因此,为自定义背景和背景指定框架 CGRectZero....
以下仅在我测试时对我有用。
UIView *bkview = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
bkview.backgroundColor = [UIColor redColor];
cell.selectedBackgroundView = bkview;
关于iphone - 关于绘制单元格矩形的解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7309580/