【问题标题】:Showing an image programmatically in tableview cell在表格视图单元格中以编程方式显示图像
【发布时间】:2009-10-12 15:10:48
【问题描述】:

我这样做是为了将图像加载到 tableview 单元格中:

UIImage *image = [UIImage imageNamed:@"myimage.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake( 0, 0, cell.frame.size.width, cell.frame.size.height );
imageView.contentMode = UIViewContentModeScaleToFill;
[cell addSubview:imageView];
[imageView release];

return cell;

但是,没有图像显示为单元格的背景。这是在一个新的导航应用程序中。当您使用自定义单元格时,上面看起来就像 Interface Builder 中的步骤。该图像位于应用程序包中。我做错了什么?

【问题讨论】:

    标签: iphone cocoa-touch uitableview uiimageview


    【解决方案1】:

    您是要设置单元格的背景,还是只是添加图像?如果你想设置它的背景,你应该使用 cell.background 属性。

    imageView.frame = cell.bounds;
    imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    cell.backgroundView = imageView;
    

    【讨论】:

    • 我试图让单元格背景成为图像。我混合了你的代码,但仍然没有图像。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多