开发者

Cannot change UIImageView frame in a custom table cell

I have a custom table cell. In i开发者_如何转开发t I have put (via the IB) an image view of a certain frame

In 'cellForRowAtIndexPath', under certain conditions, I would like to modify the frame of this UIImageView, so I write something like:

UIImageView *imgv = (UIImageView *)[cell viewWithTag:1];
CGRect r = CGRectMake(20.0, 20.0, 10.0, 10.0);
imgv.frame = r;

But nothing expected happens (The frame does move a little though not to where I want, but doesn't change its size at all);


When you change its size, you have to setup the property to scale its content. Since you cannot do it in interface builder, you have to do it in your code:

imgv.contentMode = UIViewContentModeScaleAspectFit;

Try this:

UIImageView *imgv = (UIImageView *)[cell viewWithTag:1];
imgv.contentMode = UIViewContentModeScaleAspectFit;
CGRect r = CGRectMake(20.0, 20.0, 10.0, 10.0);
imgv.frame = r;

About the position, I'm not sure why it is not working. Can you confirm if still doesn't work?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜