Unable to change UIImageView frame in user table cell

I have a custom table cell. In it I put (via IB) an image in a specific frame

In 'cellForRowAtIndexPath', under certain conditions, I would like to change the frame of this UIImageView, so I am writing something like:

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

But nothing is expected (the frame moves a little, but not where I want, but does not change its size at all);

+3
source share
1 answer

When you resize, you need to configure the property to scale its contents. Since you cannot do this in the interface builder, you must do this in your code:

imgv.contentMode = UIViewContentModeScaleAspectFit;

Try the following:

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

, , . , ?

0

Source: https://habr.com/ru/post/1782962/


All Articles