Easy Tutorial
❮ Ios Sqlite Ios Application Debugging ❯

Usage of Image View

An image view is used to display a single image or a sequence of images for animations.

Important Properties


Important Methods

- (id)initWithImage:(UIImage *)image
- (id)initWithImage:(UIImage *)image highlightedImage:(UIImage *)highlightedImage
- (void)startAnimating
- (void)stopAnimating

Adding 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];
}

Adding Another Custom Method addImageViewWithAnimation

This method explains how to animate images within an 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 must add images named "AppleUSA1.jpg" and "AppleUSA2.jpg" to our project by dragging them into our navigation area where our project files are listed.

Update viewDidLoad in ViewController.m as follows:

(void)viewDidLoad
{
   [super viewDidLoad];
   [self addImageView];
}
❮ Ios Sqlite Ios Application Debugging ❯