我有一堆图像用于单元格的 ImageView ,它们都不大于 50x50。例如40x50、50x32、20x37 .....
当我加载表格 View 时,文本没有对齐,因为图像的宽度不同。此外,我希望小图像出现在中心而不是左侧。
这是我在“cellForRowAtIndexPath”方法中尝试的代码
cell.imageView.autoresizingMask = ( UIViewAutoresizingNone );
cell.imageView.autoresizesSubviews = NO;
cell.imageView.contentMode = UIViewContentModeCenter;
cell.imageView.bounds = CGRectMake(0, 0, 50, 50);
cell.imageView.frame = CGRectMake(0, 0, 50, 50);
cell.imageView.image = [UIImage imageWithData: imageData];
如你所见,我尝试了一些方法,但都没有奏效。
最佳答案
没有必要重写所有内容。我建议这样做:
将此发布在您的自定义单元格的 .m 文件中。
- (void)layoutSubviews {
[super layoutSubviews];
self.imageView.frame = CGRectMake(0,0,32,32);
}
这应该可以很好地解决问题。 :]
关于iphone - 即使图像较小,如何使 UITableViewCell 的 ImageView 成为固定大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2788028/