我想将附件图像的背景定义到我的UITableViewCell。我正在尝试使用下面的代码,但没有成功。
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"teste1.png"]];
我的UITableView是一个分组和静态的。我还尝试定义tableView.backgroundcolor来清除颜色,但也没有成功。
任何帮助将不胜感激。 谢谢, 马科斯
答案 0 :(得分:1)
试试这个......
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"YOUR_IMAGE.png"]];
答案 1 :(得分:0)
在Apple的UITableViewCell文档中,关于backgroundView:
对于普通样式表(UITableViewStylePlain)中的单元格,默认值为nil;对于分组样式表UITableViewStyleGrouped,默认值为非nil。 UITableViewCell将背景视图添加为所有其他视图后面的子视图,并使用其当前帧位置。
所以我认为改变分组式表格的背景视图并不是一个好主意(这是你的情况)。尝试在背景视图上方插入新的imageView:
UIImage *background = [UIImage imageWithContentsOfFile:@"teste1"];
UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background];
[cell insertSubview:cellBackgroundView aboveSubview:cell.backgroundView];
并且不要忘记将所有视图中的颜色设置为清晰可能在上方并阻挡背景。
答案 2 :(得分:0)
我最终将UIButton放在整个UITableViewCell区域内。