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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11135583/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:39:28  来源:igfitidea点击:

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

iphoneiosxcodeuiimageicarousel

提问by Dany

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

我需要在单个视图中显示图像数组,这些图像在 icarousel(时间机器、coverflow 等...)中具有各种效果,我将使用单一样式,其中所有图像都必须显示......这是我的代码.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];

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

但它不起作用......任何人都可以帮忙......

回答by Till

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

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



Use animationImagesinstead:

使用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];


From the UIImageView documentation;

来自UIImageView 文档

animationImages

An array of UIImage objects to use for an animation.

用于动画的 UIImage 对象数组。

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

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

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

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

回答by janusfidel

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

回答by Guntis Treulands

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

看看这个简单的例子: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

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