IOS Introduction
Swift UI Label
Swift UI Button
Swift UI Text Field
Swift UI Slider
Swift UI Switch
Swift UI Stepper
Swift UI Date Picker
Swift UI Segmented Control
Table View
Collection Views
iOS Content View
iOS View Controllers
iOS Bar interface
iOS Navigation interface
iOS Architect Pattern
iOS Libraries
iOS Web request and parsing
iOS user defaults
iOS Coredata and database

Image View

Image View

ImageView is an object that may be used to show pictures on the interface of iOS applications. It's a member of the UIImageView class, which is derived from UIView. Where the UIImage object defines the image, ImageView draws the picture on the interface.

The picture view is used to show a single image or a succession of animated images.

Important Characteristics




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 demonstrates how to use imageView to animate pictures.

-(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 must add the pictures "AppleUSA1.jpg" and "AppleUSA2.jpg" to our project by dragging them to the navigator area where our project files are shown.

In ViewController.m, make the following changes to viewDidLoad:

(void)viewDidLoad { [super viewDidLoad]; [self addImageView]; }