UIImageView.image比UIImageView更大 [英] UIImageView.image bigger than UIImageView
问题描述
我在自定义tableview单元格中有一个UIImageView。当我设置UIimageview属性时,uiimageview.image比uiimageview大。为什么?
以下是代码:
I have a UIImageView in a custom tableview cell. When I set the UIimageview property, the uiimageview.image is bigger than the uiimageview. Why? Here is the code:
cell.imageView.image=[UIImage imageNamed:@"BlueMooseLogo.png"];
这是一个指向单元格的链接。蓝色方块是imageview的背景,蓝色驼鹿是图像。
https://docs.google.com/document/d / 1G7BYCriYbSGYHryP5OI7XHuVpqRKiNcBrxdY14wDgoA / edit?usp = sharing
And here is a link to what the cell looks like. The blue square is the background of the imageview, and the blue moose is the image. https://docs.google.com/document/d/1G7BYCriYbSGYHryP5OI7XHuVpqRKiNcBrxdY14wDgoA/edit?usp=sharing
如果它是相关的,在界面构建器中,在我选择uiimageview之后,我将视图设置为按比例缩放以填充。
If it's relevant, within interface builder, after I select the uiimageview, I have the view set to scale to fill.
推荐答案
我遇到了同样的问题,并尝试了很多方法来解决它,最后,我做到了。当您尝试将图像分配给UIImageView时,请将图像调整为缩略图图像,然后使用此缩略图图像进行显示。以下代码仅供您参考。
I've faced the same problem, and tried a lot ways to fix it, finally, I did it. When you try to assign the image to your UIImageView, please resize your image as a thumbnail image, and use this thumbnail image to display. The following code just for your reference.
static func resizeImage(image:UIImage, toTheSize size:CGSize) -> UIImage{
let scale = CGFloat(max(size.width/image.size.width,
size.height/image.size.height))
let width:CGFloat = image.size.width * scale
let height:CGFloat = image.size.height * scale;
let rr:CGRect = CGRectMake( 0, 0, width, height);
UIGraphicsBeginImageContextWithOptions(size, false, 0);
image.drawInRect(rr)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
return newImage
}
这篇关于UIImageView.image比UIImageView更大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!