objective-c - 在 UITableViewCell 中调整 UIImageView 的大小

标签 objective-c cocoa-touch uikit

我有一个 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/

相关文章:

iphone - 由于 DNS 查找导致 NSURLConnection 延迟?

ios - 带有 StackView 的 UITableViewCell 不能动态调整高度

objective-c - 复选标记代码错误

objective-c - 如何使用@selector调用带参数的方法

iphone - 在 ios 中更改 View 的背景图像

iphone - UISegmentedControl 选定索引始终为 0?

ios - 如何从上下文绘制的图像中获取 CGImageRef?

ios - 如何让UISlider在第一次显示的时候变粗?

iOS 设备未使用 GDAsyncUdpSocket 接收 UDP 多播

objective-c - 如何在两个 MKCoordinateRegion 之间建立联合