【问题标题】:UIImageView arrayUIImageView 数组
【发布时间】:2012-11-24 09:12:00
【问题描述】:

如何将四个图像放入一个 UIImageView 数组中? 为什么我的forloop不能运行?

如果我想用四个图像创建四个帧,该怎么做?

    NSArray *photos = [NSArray arrayWithObjects:
                    [UIImage imageNamed:@"1.jpg"],
                    [UIImage imageNamed:@"2.jpg"],
                    [UIImage imageNamed:@"3.jpg"],
                    [UIImage imageNamed:@"4.jpg"],nil]; 




    for(int i=0;i<5;i++)
   {
    UIImage *image = [UIImage imageNamed:[photos objectAtIndex:i]];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
   }

【问题讨论】:

  • 解释更多。您想使用四张图片作为动画吗?
  • 如果我添加这个forloop,它会崩溃。
  • for(int i=0;i

标签: nsstring uiimageview uiimage nsarray


【解决方案1】:
NSArray *photos = [NSArray arrayWithObjects:
                    [UIImage imageNamed:@"1.jpg"],
                    [UIImage imageNamed:@"2.jpg"],
                    [UIImage imageNamed:@"3.jpg"],
                    [UIImage imageNamed:@"4.jpg"],nil]; 
UIImageView *imgView = [[UIImageView alloc]init];
imgView.animationImages = photos;

【讨论】:

  • 我想在四个 UIImageViews 中设置四个图像,而不是设置动画图像。
  • 这不值得回答: UIImageView *imgView = [[UIImageView alloc]initWithImage:[photos objectAtIndex:0]];或者如果您已经创建了 imgView:imgView.image = [photos objectAtIndex:0];但是有些人在谷歌上搜索这个问题没有?
  • for(int i=0;i
  • imageView的作用域只在for循环内分配,退出forloop后imageView被ARC释放。
  • 谢谢你的回答,但我不知道怎么修改。你能教我吗?
【解决方案2】:

[photos objectAtIndex:i]这个方法你只能得到UIImage对象,你不能得到[UIImage imageNamed:]方法的NSString对象。

【讨论】:

  • 这是完整的解决方案吗?
猜你喜欢
  • 2010-11-17
  • 2022-06-10
  • 1970-01-01
  • 2016-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多