我有一个 16x16 像素的图像,我想在 UIImageView 中显示。到目前为止,没问题,但是 16x16 有点小,所以我想将 ImageView 的大小调整为 32x32,从而也将图像放大。 但我无法让它工作,无论我尝试什么,它总是显示 16x16 的图像。我在谷歌上搜索了很多,并在 Stack Overflow 上找到了很多片段,但它仍然不起作用。 到目前为止,这是我的代码:
[[cell.imageView layer] setMagnificationFilter:kCAFilterNearest];
[cell.imageView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
[cell.imageView setClipsToBounds:NO];
[cell.imageView setFrame:CGRectMake(0, 0, 32, 32)];
[cell.imageView setBounds:CGRectMake(0, 0, 32, 32)];
[cell.imageView setImage:image];
我不想创建一个新的 32x32 像素图像,因为我在旧设备上已经有一些内存问题并且创建两个图像而不是只创建一个图像对我来说是一个非常糟糕的方法(图像可以完美缩放和如果他们失去质量并不重要)。
最佳答案
我已经使用 CGAffineTransformMakeScale 成功制作了它!
cell.imageView.image = cellImage;
//self.rowWidth is the desired Width
//self.rowHeight is the desired height
CGFloat widthScale = self.rowWidth / cellImage.size.width;
CGFloat heightScale = self.rowHeight / cellImage.size.height;
//this line will do it!
cell.imageView.transform = CGAffineTransformMakeScale(widthScale, heightScale);
关于objective-c - 在 UITableViewCell 中调整 UIImageView 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4122958/