在iphone屏幕上显示NSArray外的索引png文件
我喜欢在iphone上创建一个艺术品计数器显示,从0到9。10位数字是10个png文件,数字为0到9,作为其艺术作品内容。这10个png文件是使用NSArray实现的。下面是实现代码:在iphone屏幕上显示NSArray外的索引png文件,iphone,png,uiimageview,nsarray,addsubview,Iphone,Png,Uiimageview,Nsarray,Addsubview,我喜欢在iphone上创建一个艺术品计数器显示,从0到9。10位数字是10个png文件,数字为0到9,作为其艺术作品内容。这10个png文件是使用NSArray实现的。下面是实现代码: zahlenArray = [NSArray arrayWithObjects: [UIImage imageNamed:@"ziffer-0.png"], [UIImage imageNamed:@"ziffer-1.png"], [UIImag
zahlenArray = [NSArray arrayWithObjects:
[UIImage imageNamed:@"ziffer-0.png"],
[UIImage imageNamed:@"ziffer-1.png"],
[UIImage imageNamed:@"ziffer-2.png"],
[UIImage imageNamed:@"ziffer-3.png"],
[UIImage imageNamed:@"ziffer-4.png"],
[UIImage imageNamed:@"ziffer-5.png"],
[UIImage imageNamed:@"ziffer-6.png"],
[UIImage imageNamed:@"ziffer-7.png"],
[UIImage imageNamed:@"ziffer-8.png"],
[UIImage imageNamed:@"ziffer-9.png"],
nil];
作为10 digitis的索引,我使用一个整数变量,用0初始化:
int counter = 0;
此外,我声明一个UIImageview程序:
UIImageView *zahlenEinsBisNeun;
UIImageview的实现代码为:
zahlenEinsBisNeun = [UIImage alloc] initWithFrame:CGRectMake(240, 50, 200, 200)];
????????????????????????????????????????
[self.view addSubview:zahlenEinsBisNeun];
[zahlenEinsBisNeun release];
在那里,你可以看到问号,我不知道如何编写代码,用索引“counter”从NSArray检索我的内容artworks 0到9,并通过使用…使其在我的iphone屏幕上可见。。。。添加子视图:zahlenEinsBisNeun
有人能帮忙吗
我提前感谢你的支持
托马斯·赫尔斯曼(Thomas Hülsmann)我不太熟悉iPhone SDK/图像属性,但您肯定会
[zahlenArray objectAtIndex:counter]
要返回所需的UI图像 首先,而不是
zahlenEinsBisNeun=[UIImage alloc]initWithFrame:CGRectMake(240,50200200)]代码>
写
然后
for(int i=0;i<10;i++)
{
UIImage*tempImage=[zahlenArray对象索引:i];
[zahlenEinsBisNeun添加子视图:tempImage];
}
[self.view addSubview:zahlenEinsBisNeun];
[zahlenEinsBisNeun释放];
在此之前,您需要调整每个图像的帧…我不确定是否理解您的问题,但我认为您应该只向子视图添加一个UIImageView,并从UIImageView更改图像字段
[self.view addSubview:zahlenEinsBisNeun];
如果您想更改此imageView中的图像,请在计时器或任何线程(在其他函数中)中:
zahlenEinsBisNeun.image = [zahlenArray objectAtIndex:counter]
问候,
[self.view addSubview:zahlenEinsBisNeun];
zahlenEinsBisNeun.image = [zahlenArray objectAtIndex:counter]