【发布时间】:2015-04-16 14:03:43
【问题描述】:
我正在通过如下 URL 设置表格单元格 ImageView:
NSURL *url = [[NSURL alloc] initWithString:[account valueForKeyPath:@"Avatar"]];
[cell.imageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"default.png"]];
然后我使用表格单元子类并调整图像大小并将其变为圆形,如下所示:
- (void)layoutSubviews {
[super layoutSubviews];
self.imageView.bounds = CGRectMake(0,0,32,32);
self.imageView.layer.cornerRadius = 16;
self.imageView.clipsToBounds = YES;
}
在我真正点击表格行之前,这非常有效。然后它将图像向左移动一些像素。
只有图像不是完美的正方形。示例 100x75 而不是 100x100
我一定是遗漏了一些小东西吗?这是一个显示偏移量的小图:
仅供参考,我引用了这篇文章:How do I make UITableViewCell's ImageView a fixed size even when the image is smaller
编辑
我也试过这个作为表格单元格cellForRowAtIndexPath:
这似乎可行,但是,由于某种原因,加载表格视图时,在我开始滚动之前,并非所有图像都已加载
[[SDWebImageManager sharedManager] downloadImageWithURL:url options:0 progress: nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
// resize image code here, then set below
cell.imageView.image = image;
}];
【问题讨论】:
-
而不是在 layoutSubviews 方法中设置边界设置框架为 self.imageView.frame = CGRectMake(0,0,32,32);
-
如果我设置框架,图像不再居中
标签: ios objective-c uitableview imageview sdwebimage