1

我知道如何以编程方式为静态 UITavleView 中的单元格设置图像:

cell.backgroundView = [ [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"image1.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]autorelease];

我可以设置背景颜色,但不能设置图像。是否可以从界面生成器中设置它?

4

2 回答 2

2

创建一个新的用户界面 Xib 文件。删除初始视图。将您的 uitableviewcell 拖放到构建器中。自定义...然后把这个放在viewDidLoad中:

 UINib *cellNib = [UINib nibWithNibName:@"pizzaCell" bundle:[NSBundle mainBundle]];
[self.tableView registerNib:cellNib
      forCellWithReuseIdentifier:@"pizzaCell"];

然后在 cellForRowAtIndexPath 中执行以下操作:

static NSString *cellIdent = @"pizzaCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdent];

现在你有了你的笔尖细胞。如果您想获取对添加到单元格的视图的引用,我这样做的方式是提供 em 标签并在单元格上调用 viewWithTag。

您可能还只是在寻找:

 cell.contentView.imageView.image = [UIImage imageNamed:@"PizzaImage"];

不确定您要自定义多少

于 2012-10-08T20:00:33.223 回答
0

可以通过连接 tableViewCell 的 backgroundView 出口(与 nib 文件中的另一个视图)。但是您不能在界面构建器中制作可拉伸的图像..

于 2012-10-08T20:09:21.830 回答