繁体   English   中英

在tableview单元格中以编程方式显示图像

[英]Showing an image programmatically in tableview cell

我这样做是为了将图像加载到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中的步骤。 该图像位于应用程序捆绑包中。 我究竟做错了什么?

您是要设置单元格的背景还是仅添加图像? 如果尝试设置其背景,则应使用cell.background属性。


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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM