How do I create a UIImageView
in code, instead of creating it in my xib file?
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage . Save this answer.
A view that displays a single image or a sequence of animated images in your interface.
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.
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.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With