我有一个显示用户图像,名称和一些文本的表格单元格。用户的图像是50x50,但我想要一个边框,所以我将视图设置为居中图像并将帧设置为52x52,然后将该视图的背景颜色设置为我的边框颜色。这显示了图像周围的1像素边框。UITableViewCell的selectedBackgroundView获取应用于单元格中的所有视图
我也想在单元格被选中时在单元格的右边显示一个30像素宽的边框。我试图通过创建一个UIView单元框架的大小,然后添加一个子视图到UIView的宽度和背景颜色,我想。然后我将该视图设置为单元格的selectedBackgroundView。
这里的问题是,单元格的selectedBackgroundView被应用到单元格内所有视图的背景。所以当我选择一个单元格时,图像“边框”被设置为单元格的选定背景颜色,我添加的另一个30像素“边框”也被更改为该背景颜色。
代码我的cellForRowAtIndexPath里面:
cell = (UserCellView *) currentObject;
UIView *c = [[UIView alloc ] initWithFrame:CGRectMake(0, 0, 30, cell.frame.size.height)];
c.backgroundColor = [[UIColor alloc] initWithRed:64/255.0 green:64/255.0 blue:64/255.0 alpha:1.0];
UIView *v = [[UIView alloc ] initWithFrame:cell.frame];
v.backgroundColor = [[UIColor alloc] initWithRed:35/255.0 green:35/255.0 blue:35/255.0 alpha:1.0];
[v addSubview:c];
cell.selectedBackgroundView = v;
[c release];
[v release];
你能有更多的解释?我如何设置contentView上的backgroundView? – JasonB 2010-10-29 15:32:47