Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create UIImageView

How do I create a UIImageView in code, instead of creating it in my xib file?

like image 381
gadgetmo Avatar asked Oct 25 '11 15:10

gadgetmo


People also ask

What is the difference between a UIImage and a UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage . Save this answer.

What is UIImageView in Swift?

A view that displays a single image or a sequence of animated images in your interface.

What is use of UIImageView?

Whenever you want an image in a view controller, you use a UIImageView. A UIImageView contains a UIImage, which is the raw bitmap, and allows you to configure how you want to scale or crop the image.

How do I add actions to UIImageView?

Open the Library, look for "Tap Gesture Recognizer" object. Drag the object to your storyboard, and set the delegate to the image you want to trigger actions. Then go to the view controller, drag the same object to set the IBAction.


1 Answers

You can create seperately a UIImage, and create your UIImageView from your UIImage.

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

Then, set the size of your UIImageView

[myImageView setFrame:CGRectMake(0, 0, 100, 200)];

Do whatever you want with your image, but don't forget to release it.

[anotherView addSubview:myImageView];
[myImageView release];
like image 88
NSZombie Avatar answered Oct 03 '22 15:10

NSZombie