iphone - Random image display using rand() -
I'm just SDK and trying to learn Objesi 2, hatred around with little apps.
Im trying to display an image randomly and I find different ways to display a picture. I have uploaded the image to the SDK resource folder.
Anyway, this is my code, can someone run me in the right direction.
#import "randomViewController.h" @implementation randomViewController // is not sure that it really is the right way to do this is NSArray * comImage = [NSArray arrayWithObjects: [UIImage imageNamed: @ "rock .png "], [UIImage imageNamed: @" paper.png "], [UIImage imageNamed: @" scissors.png "], zero]; - (IBAction) Randton {int text = rand ()% 3; Switch (text) {case 0: textView.text = @ "rock"; break; Case 1: textView.text = @ "Paper"; break; Case 2: textView.text = @ "" Scissor "; break; default: brake;}}
I it would like:
NSArray * myImageNames = [NSArray arrayWithObjects: @ "rock.png", @ "paper.png", @ "scissors.png", zero ]; Int index = arc4random ()% [myImageNames count]; UIImage * myImage = [UIImage image named: [myImageNames Objektaetindaks: Index]]; MyUIImageView.image = myImage;
of course You can keep your INGJnames so that you do not have to fix it every single run.
Edit:
see it was updated code assumes that you have already UIImageView to myUIImageView is added to your scene. I believe that that is how you got UIButton on screen before.
announce UIImageView * myUIImageView in its header. it Deedlod using you xib that you feel in your view:
MyUIImageView = [[UIImageView alloc] initWithFrame: CGRectMake (X, Y, width, height)]; [Self.view addSubview: myUIImageView];
Replace x, y, width, and height with appropriate values They will determine where UIImageView appears and how big it is.
Comments
Post a Comment