在 iPhone 屏幕上显示 NSArray 中的索引 png 文件

发布于 2024-08-26 14:16:05 字数 1311 浏览 7 评论 0原文

我喜欢在iPhone上创建一个艺术品柜台显示器,显示0到9。这10位数字是10个png-文件,其中数字0到9作为其艺术品内容。这10个png-文件是使用NSArray实现的。下面你会找到实现代码:

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 位数字的索引,我使用一个整数变量,用 0 初始化:

int counter = 0;

此外,我以编程方式声明一个 UIImageview:

UIImageView *zahlenEinsBisNeun;

UIImageview 的实现代码是:

zahlenEinsBisNeun = [UIImage alloc] initWithFrame:CGRectMake(240, 50, 200, 200)];

????????????????????????????????????????

[self.view addSubview:zahlenEinsBisNeun];
[zahlenEinsBisNeun release];

在那里,你看到问号,我不知道如何编写代码,使用索引“计数器”从 NSArray 检索我的内容艺术品 0 到 9,并使用 ....addSubview:zahlenEinsBisNeun ...使其在我的 iphone 屏幕上可见...

任何人都可以帮忙吗???

感谢您提前提供的支持

Thomas Hülsmann

i like to create an artwork counter- display on an iphone, diplaying 0 to 9. The 10 digits are 10 png- files with the numbers 0 to 9 as their artwork content. The 10 png- files are implemented by using NSArray. Following you'll find the implementation- code:

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

As an index for the 10 digitis I use an integer variable, initializing with 0:

int counter = 0;

Furthermore I declare an UIImageview programmaticaly:

UIImageView *zahlenEinsBisNeun;

The implementation code for the UIImageview is:

zahlenEinsBisNeun = [UIImage alloc] initWithFrame:CGRectMake(240, 50, 200, 200)];

????????????????????????????????????????

[self.view addSubview:zahlenEinsBisNeun];
[zahlenEinsBisNeun release];

There, where you see the questionmarks, I don't know how to write the code, to retrieve my content artworks 0 to 9 from NSArray with the index "counter" and make it visible on my iphone screen by using .... addSubview:zahlenEinsBisNeun ...

Can anybody help???

My thanks for your support in advance

Thomas Hülsmann

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

面犯桃花 2024-09-02 14:16:05

首先,而不是 zahlenEinsBisNeun = [UIImage alloc] initWithFrame:CGRectMake(240, 50, 200, 200)];
那么

zahlenEinsBisNeun = [UIImageView alloc] initWithFrame:CGRectMake(240, 50, 200, 200)];

......

for(int i = 0; i < 10 ; i++)
{
      UIImage *tempImage = [zahlenArray objectAtIndex:i];
      [zahlenEinsBisNeun addSubview:tempImage];
}
[self.view addSubview:zahlenEinsBisNeun];
[zahlenEinsBisNeun release];

你需要在此之前调整每个图像的帧

first of all instead of zahlenEinsBisNeun = [UIImage alloc] initWithFrame:CGRectMake(240, 50, 200, 200)];
write

zahlenEinsBisNeun = [UIImageView alloc] initWithFrame:CGRectMake(240, 50, 200, 200)];

then

for(int i = 0; i < 10 ; i++)
{
      UIImage *tempImage = [zahlenArray objectAtIndex:i];
      [zahlenEinsBisNeun addSubview:tempImage];
}
[self.view addSubview:zahlenEinsBisNeun];
[zahlenEinsBisNeun release];

you'll need to adjust frame of each image before this...

吃素的狼 2024-09-02 14:16:05

我不太熟悉 iPhone SDK/图像属性,但你肯定只是

[zahlenArray objectAtIndex:counter]

返回你想要的 UI 图像吗?

I'm not to familiar with the iPhone SDK/image properties but surely you'd just

[zahlenArray objectAtIndex:counter]

to return the UI image you want?

椵侞 2024-09-02 14:16:05

我不确定我是否理解你的问题,但我认为你应该只添加一个 UIImageView 到子视图,并从 UIImageView

[self.view addSubview:zahlenEinsBisNeun];

和计时器或任何线程(在其他函数中)更改 IMAGE 字段,如果你想更改此 imageView 中的图像:

zahlenEinsBisNeun.image = [zahlenArray objectAtIndex:counter]

问候,

I'm not sure that i understand you problem, but i think you should add only one UIImageView to subview and change IMAGE field from UIImageView

[self.view addSubview:zahlenEinsBisNeun];

and in timer or any thread (in other function) if you want change your images in this imageView:

zahlenEinsBisNeun.image = [zahlenArray objectAtIndex:counter]

regards,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文