Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 以编程方式创建新的UIImageView_Iphone_Objective C_Ios_Xcode_Uiimageview - Fatal编程技术网

Iphone 以编程方式创建新的UIImageView

Iphone 以编程方式创建新的UIImageView,iphone,objective-c,ios,xcode,uiimageview,Iphone,Objective C,Ios,Xcode,Uiimageview,我想知道一个在运行时创建新UIImageView的循环。我希望每个UiImageView都有不同的名称。如果用户指定他们想要100张图像,则在屏幕的特定区域中放置100张图像的大小是适当的。他们需要装满一个罐子。类似于星巴克手机卡应用程序的stars部分,除了有一个无限的关于可能的图像 我该怎么做 编辑:图像视图应放在下面的Jar中: 谢谢您可以使用for循环和NSMutableArray创建多个UIImageViews,如下所示: NSMutableArray *imagesArray =

我想知道一个在运行时创建新UIImageView的循环。我希望每个UiImageView都有不同的名称。如果用户指定他们想要100张图像,则在屏幕的特定区域中放置100张图像的大小是适当的。他们需要装满一个罐子。类似于星巴克手机卡应用程序的stars部分,除了有一个无限的关于可能的图像

我该怎么做

编辑:图像视图应放在下面的Jar中:


谢谢

您可以使用
for
循环和
NSMutableArray
创建多个
UIImageView
s,如下所示:

NSMutableArray *imagesArray = [[NSMutableArray alloc] init];
for (int i=0; i<100; ++i) {
    UIImageView *imgView = [[UIImageView alloc] init];
    // customize the UIImageView as you like
    [imagesArray addObject:imgView];
    [imgView release];
}
NSMutableArray*imagesArray=[[NSMutableArray alloc]init];

对于(int i=0;i关于内存问题的底线:不允许无限数量的图像

  • 如果图像填满了一个罐子,为了逼真,你必须有重叠。如果所有图像都同时显示在屏幕上,用户根本无法看到100个不同的图像

  • 限制用户。你需要摆脱无限的概念。然后你就没事了。你真正想要的是让你的程序显示大量的图像。我不确定你是否打算允许缩放-这会让事情复杂得多-但在iPho上显示100幅图像不包括你提到的jar,大小相等的ne屏幕是48像素乘32像素。这已经相当小了

  • 我们确实需要更多信息,以便就如何处理此问题向您提供建议。您是否打算允许缩放?图像是否重叠?您打算将最小尺寸设置为多小?等等

  • 对于多个图像视图,PengOne是正确的

    这将把映像添加到NSMutableArray中

    NSMutableArray*imagesArray=[[NSMutableArray alloc]init];
    
    对于(int i=0;ii如果要执行此操作,请注意内存占用并对内存警告做出反应,否则您会遇到麻烦。只加载实际需要显示的图像视图的图像。是否有方法可以立即释放/删除它们?因此,如果要使用页控制器,我只需分配原始数组?Looks喜欢内存问题。带有
    image
    属性集的100个UIImageView很可能会使你的应用程序崩溃。你可能需要保留数据并根据需要重新创建。@PengOne,有没有办法将图像保留在屏幕的某个区域?@AhanMalhotra将它们放在UIScrollView中我对PengOnes code
    NSMutableArray*imag做了一些更改esArray=[[NSMutableArray alloc]init];while(loop我真的不明白while循环比他的for循环有什么好处。这似乎是您所做的唯一更改。如何将图像视图添加到屏幕(或其他视图/滚动视图)?谢谢![ViewToAddSubView:imageView];这是我的代码:`NSMutableArray*imagesArray=[[NSMutableArray alloc]init];for(int i=0;i
    
    NSMutableArray *imagesArray = [[NSMutableArray alloc] init];
    for (int i=0; i<100; ++i) {
        UIImageView *imgView = [[UIImageView alloc] init];
        // customize the UIImageView as you like
        [imagesArray addObject:imgView];
        [imgView release];
    }