
- iOS Tutorial
- iOS - Home
- iOS - Getting Started
- iOS - Environment Setup
- iOS - Objective-C Basics
- iOS - First iPhone Application
- iOS - Actions and Outlets
- iOS - Delegates
- iOS - UI Elements
- iOS - Accelerometer
- iOS - Universal Applications
- iOS - Camera Management
- iOS - Location Handling
- iOS - SQLite Database
- iOS - Sending Email
- iOS - Audio & Video
- iOS - File Handling
- iOS - Accessing Maps
- iOS - In-App Purchase
- iOS - iAd Integration
- iOS - GameKit
- iOS - Storyboards
- iOS - Auto Layouts
- iOS - Twitter & Facebook
- iOS - Memory Management
- iOS - Application Debugging
- iOS Useful Resources
- iOS - Quick Guide
- iOS - Useful Resources
- iOS - Discussion
iOS - Image View
Use of Image View
Image view is used for displaying a single image or animated sequence of images.
Important Properties
- image
- highlightedImage
- userInteractionEnabled
- animationImages
- animationRepeatCount
Important Methods
- (id)initWithImage:(UIImage *)image - (id)initWithImage:(UIImage *)image highlightedImage: (UIImage *)highlightedImage - (void)startAnimating - (void)stopAnimating
Add a Custom Method addImageView
-(void)addImageView { UIImageView *imgview = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 300, 400)]; [imgview setImage:[UIImage imageNamed:@"AppleUSA1.jpg"]]; [imgview setContentMode:UIViewContentModeScaleAspectFit]; [self.view addSubview:imgview]; }
Add Another Custom Method addImageViewWithAnimation
This method explains how to animate images in imageView.
-(void)addImageViewWithAnimation { UIImageView *imgview = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 300, 400)]; // set an animation imgview.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"AppleUSA1.jpg"], [UIImage imageNamed:@"AppleUSA2.jpg"], nil]; imgview.animationDuration = 4.0; imgview.contentMode = UIViewContentModeCenter; [imgview startAnimating]; [self.view addSubview:imgview]; }
Note −
We have to add images named as "AppleUSA1.jpg" and "AppleUSA2.jpg" to our project, which can be done by dragging the image to our navigator area where our project files are listed.
Update viewDidLoad in ViewController.m as follows −
(void)viewDidLoad { [super viewDidLoad]; [self addImageView]; }
Output
When we run the application, we'll get the following output −

You can try calling addImageViewWithAnimation instead of addImageView method to see the animation effect of image view.
ios_ui_elements.htm
Advertisements