Jus*_*Sid 8 cocoa-touch objective-c uikit
我有一个16x16像素的图像,我想在UIImageView中显示.到目前为止,没问题,但是16x16有点小,所以我想将图像视图调整为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];
Run Code Online (Sandbox Code Playgroud)
我不想创建一个新的32x32像素图像,因为我已经在旧设备上有一些内存问题并且创建了两个图像而不是只有一个看起来像我的非常糟糕的方法(图像可以完美缩放,它不会'无论质量如何都很重要).
Ahm*_*med 30
我已成功使用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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18726 次 |
| 最近记录: |