jovany
jovany

Reputation:

Does anyone know how I can get the "real" size of the UIImageView instead of creating a frame

I was hoping there was some sort of function that could take the real size of my picture

CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0, 210.0f);  // 234
            UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];

            [myImage setImage:[UIImage imageNamed:@"start.png"]];

And with CGRectMake which does something like this ..( imageViewHeight ,

CGFloat imageViewHeight = [myImage frame].size.height;

So that I could get the real size instead of having to define it like you can seen above.

Upvotes: 1

Views: 577

Answers (3)

Emin Bugra Saral
Emin Bugra Saral

Reputation: 3786

As far as I understood, you are looking for the size of the image used in UIImageView object. To do that, there is not a function built in UIImageView but you can do it this way:

NSString* image= [myImage image].accessibilityIdentifier; // Get the image's name
UIImage *img = [UIImage imageNamed:image]; // Create an image object with that name
CGSize size = img.size; // Get the size of image

Hope this helps your question.

Upvotes: 0

David Kanarek
David Kanarek

Reputation: 12613

It looks like you're asking to add the image to the imageview without first creating a frame. If this is the case, you can do the following:

UIImageView *myImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"start.png"]];

Upvotes: 1

Dave DeLong
Dave DeLong

Reputation: 243156

I don't really get what you're asking, but here's a shot:

If you have a UIImage, and you want to know its size, you can ask it for its -[UIImage size] property.

However, if you want to create a UIImageView that's the same size as a UIImage, then you can just use -[UIImageView initWithImage:], which will automatically set the frame of the UIImageView to correspond to the dimensions of the image.

If, however, you're just looking to change the dimensions of a currently existing view, there's really no easy way to do that without messing around with the view's frame. You could maybe apply an affine transform to scale it, but it's easier to manipulate the frame.

Upvotes: 1

Related Questions