如何在ios4中以编程方式将图像数组添加到UIImage视图?

Dan*_*any 5 iphone xcode uiimage ios icarousel

我需要在单个视图中显示图像数组,这些图像在icarousel(时间机器,封面流等等)中具有各种效果.我将使用单一样式,其中所有图像都必须显示..这是我的代码.M文件..

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];
Run Code Online (Sandbox Code Playgroud)

但它没有用......任何人都可以帮忙...

Til*_*ill 6

更新:根据您最新的编辑,您的问题完全改变了,因此我的答案不适用.


animationImages改为使用:

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];
Run Code Online (Sandbox Code Playgroud)

来自UIImageView文档 ;

animationImages
Run Code Online (Sandbox Code Playgroud)

用于动画的UIImage对象数组.

@property(nonatomic, copy) NSArray *animationImages
Run Code Online (Sandbox Code Playgroud)

讨论数组必须包含UIImage对象.您可以在阵列中多次使用相同的图像对象.将此属性设置为nil以外的值会隐藏image属性表示的图像.默认情况下,此属性的值为nil.

可用性适用于iOS 2.0及更高版本.另请参见@property image @property contentMode(UIView)在UIImageView.h中声明