Search code examples
iphoneiosxcodeuiimageicarousel

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...


Solution

  • 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