tags:

views:

198

answers:

2

How do UIImageView autoresize according to UIImage's size?

imageView.image = image2;

Now, the size of image2 is (Width = 123.0; height = 123.0); and the size of imageView is (Width = 18;height=18); My problem is, could imageView autoresize to (123.0,123.0) ? I have all type of the property UIViewContentMode, but imageView didn't change its size.

A: 

you can alter imageView.frame=CGRectMake(position.x,position.y,size.x,size.y);

jAmi
A: 

You can subclass UIImageView (say, AutoresizedImageView) and override -setImage: method in it:

- (void)setImage:(UIImage*)image{
    [super setImage:image];
    self.bounds = CGRectMake(0, 0, image.size.width, image.size.height);
}

Haven't tried it myself but I think it should work fine

Vladimir