iphone - 即使图像较小,如何使 UITableViewCell 的 ImageView 成为

我有一堆图像用于单元格的 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/

相关文章:

ios - 如何检查 View Controller 是否以模态方式呈现或推送到导航堆栈上?

objective-c - 抑制警告 "Category is implementing a met

objective-c - Swift native 基类或 NSObject

ios - 键盘出现时如何滚动 UIScrollView?

iphone - 为 UIView 子类加载 Nib 的正确方法

ios - 正确使用 beginBackgroundTaskWithExpirationHandle

iphone - 我在 iPhone 上的日期字符串中使用什么格式的字符串来表示毫秒?

objective-c - 如何在 Objective-C 中检测未使用的方法和#import

objective-c - 如何将 int 转换为 NSString?

objective-c - iOS 6 中用于完成 block 的 dispatch_get_cur