Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add array of images to UIImage view programmatically in ios4?

I need to display array of images in a single view which have various effect in icarousel(time machne,coverflow,etc...)i'm going to use single style where all images have to be displayed.. HERE IS MY CODE IN .M FILE..

UIImage *img=[[UIImageView alloc]initWithFrame:CGRectMake(30, 30, 290, 400)];
NSLog(@"hi");

img.image=[NSArray arrayWithObjects:[UIImage imageNamed:@"Cover_0.png"],
                      [UIImage imageNamed:@"Cover_1.png"],
                      [UIImage imageNamed:@"Cover_2.png"],
                      [UIImage imageNamed:@"Cover_3.png"],
                      [UIImage imageNamed:@"Cover_4.png"],
                      [UIImage imageNamed:@"Cover_5.png"],
                      [UIImage imageNamed:@"Cover_6.png"],
                      [UIImage imageNamed:@"Cover_7.png"],nil];

But its not working...Can anyone help it out...

like image 469
Vishnu Avatar asked Jun 21 '12 09:06

Vishnu


3 Answers

Update: As per your latest edit, your question entirely changed, hence my answer does not apply.


Use animationImages instead:

UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(30, 30, 290, 400)];
img.animationImages=[NSArray arrayWithObjects:[UIImage imageNamed:@"Cover_0.png"],
                      [UIImage imageNamed:@"Cover_1.png"],
                      [UIImage imageNamed:@"Cover_2.png"],
                      [UIImage imageNamed:@"Cover_3.png"],
                      [UIImage imageNamed:@"Cover_4.png"],
                      [UIImage imageNamed:@"Cover_5.png"],
                      [UIImage imageNamed:@"Cover_6.png"],
                      [UIImage imageNamed:@"Cover_7.png"],nil];

From the UIImageView documentation;

animationImages

An array of UIImage objects to use for an animation.

@property(nonatomic, copy) NSArray *animationImages

Discussion The array must contain UIImage objects. You may use the same image object more than once in the array. Setting this property to a value other than nil hides the image represented by the image property. The value of this property is nil by default.

Availability Available in iOS 2.0 and later. See Also @property image @property contentMode (UIView) Declared In UIImageView.h

like image 132
Till Avatar answered Oct 19 '22 23:10

Till


Have you tried

   NSArray *frames = [NSArray arrayWithObjects:
   [UIImage imageWithName:@"a.png"],
   [UIImage imageWithName:@"b.png"],
   [UIImage imageWithName:@"c.png"],
   [UIImage imageWithName:@"d.png"],
   [UIImage imageWithName:@"e.png"],
   nil];

   UIImageView *animatedIMvw = [[UIImageView alloc] init];
   animatedIMvw.animationImages = frames;
   [animatedIMvw startAnimating];
like image 44
janusfidel Avatar answered Oct 19 '22 23:10

janusfidel


Check out this simple example: http://appsamuck.com/day2.html

EDIT

It appears that the homepage got broken, so check this out instead:

http://web.archive.org/web/20090207210729/http://appsamuck.com/day2.html

like image 38
Guntis Treulands Avatar answered Oct 19 '22 23:10

Guntis Treulands