设置自定义表视图单元格的背景图像 [英] Setting background image of custom table view cells

查看:117
本文介绍了设置自定义表视图单元格的背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了许多方法来设置未选择的表格单元格的背景图片,但没有成功:

I've tried numerous ways of setting the background image of an unselected table cell, but without success:

1- In IB setting the image field
2- cell.contentView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"list.png"]];
3- cell.imageView.image = [UIImage imageNamed:@"list_selected.png"];

似乎都失败了。所选单元格的图像设置有效,但不适用于未选择的单元格。

All seem to fail. The image setting for selected cell works, but not for an unselected cell. Anyone having any idea what might be wrong here?

感谢

推荐答案

尝试将backgroundView设置为imageView的图像。

Try setting the backgroundView to an imageView of the image.

来自Jason Moore的代码示例(使用TomH的更正):

Code example from Jason Moore (with TomH's correction):

cell.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"foo.png"]] autorelease];

这篇关于设置自定义表视图单元格的背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆