开发者

Displaying indexed png- files out of NSArray on the iphone screen

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:开发者_C百科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


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


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?


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,

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜