no

How to Create an Image Slide Show in Iphone Using Xcode

Here's how you can create image slide show from xcode - iphone Requirement:  -3 png images. 1.) Create a new View-based application...

Here's how you can create image slide show from xcode - iphone

Requirement:
 -3 png images.

1.) Create a new View-based application project. Name it AnimationDemo.
2.) Once the new project is created. Add the 3 png images to the Resources folder.

3.) Open the NIB Files folder.

4.) Double click on the AnimationDemoViewController.xib

5.) Make sure that the "File's Owner" is selected in the Document Window. If not visible press Option + Command + Up Button. You can make certain window visible by clicking on the Tools menu. We need to add outlets.
    a.) In the "Class Outlets" panel add imageView->UIImageView

    b.) In the menu select File->Write Class Files
    c.) Click replace, take note it will delete the old files. You can also select merge and chose left.

6.) In the AnimationDemoViewController, you will notice the entry: IBOutlet UIImageView *imageView;

 7.) Now go back to the Interface Builder, go to menu Tools->Library. Open Media and drag 1.png in the view.

8.) Select File's Owner, and in the Connections Inspector tab connect the imageView outlet to the UIImage in the view.

9.) Now copy the following code:
AnimationDemoViewController.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface AnimationDemoViewController : UIViewController {
    IBOutlet UIImageView *imageView;
}

@property(nonatomic, retain) IBOutlet UIImageView *imageView;

@end

AnimationDemoViewController.m
#import "AnimationDemoViewController.h"

@implementation AnimationDemoViewController
@synthesize imageView;

-(void)viewDidLoad {
    imageView.animationImages = [NSArray arrayWithObjects:
                                 [UIImage imageNamed:@"1.png"],
                                 [UIImage imageNamed:@"2.png"],
                                 [UIImage imageNamed:@"3.png"], nil];
    imageView.animationDuration = 1.00; //1 second
    imageView.animationRepeatCount = 0; //infinite
    
    [imageView startAnimating]; //start the animation
}

-(void)dealloc {
    [super dealloc];
    [imageView release];
}

@end

Related

xcode 7271449237924043281

Post a Comment Default Comments

6 comments

wimc said...

I'm using XCode 4 and can't really follow you through this. I completely lose you at point 5, which I assume is different in XCode 4, and then at point 6 I am completely lost.

"6.) In the AnimationDemoViewController, you will notice the entry: IBOutlet UIImageView *imageView;"

Are you referring to AnimationDemoViewController.h? AnimationDemoViewController.m? The properties of
AnimationDemoViewController.xib ?

czetsuya said...

Do you have Outlets in your interface builder? On #6, I'm referring to .h file, where imageView is automatically created after File->Write class.

Ankit J said...

What platform you are using to create the project.

Bill said...

Can we use JPG image to do the same?

Anonymous said...

How can you let the photo's change smooth? Now it's bang and switch, bang and switch ...

Anonymous said...

Nice tutorial.

item