uitableviewcell自定义背景问题 [英] uitableviewcell custom background issue
问题描述
我有一个分组的表格视图,每个部分都有一行.我将单元格的backgroundview设置为我的自定义图像,并希望以这种方式呈现该行:
I have a grouped tableview where I have one row in each section. I am setting the backgroundview of the cell to my custom image and I wish the row is rendered this way:
但是它是这样渲染的(注意没有阴影,它是平坦的):
But it renders like this (notice the absence of shadows, it's flat):
这是cellforRowAtIndexPath中的代码:
Here's the code in cellforRowAtIndexPath:
((UIImageView *)cell.backgroundView).image = [UIImage imageNamed:@"BGImage"];
其中BGImage是本文中的第一张图像,带有阴影.我在这里想念什么?
Where BGImage is the first image in this post, with shadows. What am I missing here?
推荐答案
您必须使用UITableView的波纹管委托方法设置单元格背景:-
you have to set Your Cell Background using bellow Delegate Method of 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];
}
您遇到的问题可能是图像高度
宽度
和单元格 height
width
不同
at your issue may be your image Height
width
and your cell height
width
not same
我在项目集中使用以下方法,并在Cell中设置了波纹管阴影图像:-
I am using above method in my project set with bellow shaded image set in Cell:-
及其在项目中的外观:-
and its look like in project :-
这篇关于uitableviewcell自定义背景问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!