I have a UITableViewCell with a image in it. For some reason whatever UIImage I assign to it, it will not resize.
我有一个带有图像的UITableViewCell。出于某种原因,无论我分配给它的UIImage,它都不会调整大小。
So I have some simple code like this:
所以我有一些像这样的简单代码:
((BubbleCell *)cell).bubbleImage.image = newUIImage;
Here bubbleImage is a UIImageView, a member of BubbleCell(UITableViewCell). When I assign the image to it, it is always the original size. I want to stretch it. How?
这里bubbleImage是一个UIImageView,是BubbleCell(UITableViewCell)的成员。当我为其分配图像时,它始终是原始大小。我想伸展它。怎么样?
I've tried setting the frame of the UIImageView, doesn't help
我试过设置UIImageView的框架,没有帮助
((BubbleCell *)cell).bubbleImage.frame = CGRectMake(0, 0, 100, 100);
I then actually tried add the UIImageView as a subview directly and that works like this:
然后我实际上尝试直接添加UIImageView作为子视图,其工作方式如下:
[cell addSubview: resizedImageView];
However, I don't want to be adding subview each time cellForRowAtIndexPath is called. It will be hard to layout all the different views inside the cell.
但是,我不希望每次调用cellForRowAtIndexPath时都添加子视图。很难在单元格内布置所有不同的视图。
Please help!
2 个解决方案
#1
The default contentMode value, UIViewContentModeScaleToFill, should do what you want when you resize the UIImageView frame like:
默认的contentMode值UIViewContentModeScaleToFill应该在调整UIImageView框架大小时执行以下操作:
((BubbleCell *)cell).bubbleImage.frame = CGRectMake(0, 0, 100, 100);
Are you modifying this property anywhere?
你在哪里修改这个属性?
#2
in your custom cell class find the property of uiimageview scaletofill like we do in interface builder..then set the property to yes
在你的自定义单元类中找到uiimageview scaletofill的属性,就像我们在界面构建器中那样。然后将属性设置为yes
#1
The default contentMode value, UIViewContentModeScaleToFill, should do what you want when you resize the UIImageView frame like:
默认的contentMode值UIViewContentModeScaleToFill应该在调整UIImageView框架大小时执行以下操作:
((BubbleCell *)cell).bubbleImage.frame = CGRectMake(0, 0, 100, 100);
Are you modifying this property anywhere?
你在哪里修改这个属性?
#2
in your custom cell class find the property of uiimageview scaletofill like we do in interface builder..then set the property to yes
在你的自定义单元类中找到uiimageview scaletofill的属性,就像我们在界面构建器中那样。然后将属性设置为yes