关于绘制单元格矩形的解决方案的浅谈 [英] Light about a solution to draw cell rectangles
本文介绍了关于绘制单元格矩形的解决方案的浅谈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
阅读这篇文章后,我尝试使用此解决方案.这是我的代码,在tableViewDelegate方法中:
After reading this post, i tried to use this solution. Here is my code, in the tableViewDelegate methods:
- (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"]]];
}
但是不幸的是,它没有任何改变.你知道我在做什么错吗?
But unfortunately it doesn't change anything. Do you know what I am doing wrong ?
推荐答案
我相信无论何时创建视图,都应该为此指定一些框架. 因此,为自定义背景和背景都指定框架CGRectZero....
I believe that whenever make views then you should specify some frame for that. So specify frame CGRectZero for both custom background and background....
下面的内容在我测试时对我有用.
Following just work for me when I tested.
UIView *bkview = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
bkview.backgroundColor = [UIColor redColor];
cell.selectedBackgroundView = bkview;
这篇关于关于绘制单元格矩形的解决方案的浅谈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文