[英]uitableviewcell custom background issue
I have a grouped tableview where I have one row in each section. 我有一个分组的tableview,在每个节中都有一行。 I am setting the backgroundview of the cell to my custom image and I wish the row is rendered this way:
我将单元格的backgroundview设置为我的自定义图像,并希望以这种方式呈现该行:
But it renders like this (notice the absence of shadows, it's flat): 但是它是这样渲染的(注意没有阴影,它是平坦的):
Here's the code in cellforRowAtIndexPath: 这是cellforRowAtIndexPath中的代码:
((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"BGImage"];
Where BGImage is the first image in this post, with shadows. 其中BGImage是此帖子中的第一张图像,带有阴影。 What am I missing here?
我在这里想念什么?
you have to set Your Cell Background using bellow Delegate Method of UITableView:- 您必须使用UITableView的波纹管代表方法设置单元格背景:-
- (void)tableView: (UITableView*)tableView
willDisplayCell: (UITableViewCell*)cell
forRowAtIndexPath: (NSIndexPath*)indexPath
{
UIImage *img = [UIImage imageNamed:@"yourImage.png"]; // get your background image
UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage: img];
cell.backgroundColor = backgroundColor;
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
}
at your issue may be your image Height
width
and your cell height
width
not same 在您的问题可能是您的图像
Height
width
和您的单元格height
width
不一样
I am using above method in my project set with bellow shaded image set in Cell:- 我在项目集中使用上述方法,并在Cell中设置了波纹管阴影图像集:-
and its look like in project :- 它看起来像项目中的:-
UITableViewCell
. UITableViewCell
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.