0
UILabel *scoreLabel = [ [UILabel alloc ] initWithFrame:CGRectMake((self.bounds.size.width / 2), 0.0, 150.0, 43.0) ]; 

scoreLabel.textAlignment =  UITextAlignmentCenter; 

scoreLabel.textColor = [UIColor whiteColor]; 

scoreLabel.backgroundColor = [UIColor blackColor]; 

scoreLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:(36.0)]; 

[self addSubview:scoreLabel]; 

scoreLabel.text = [NSString stringWithFormat: @"%d", score]; 

Can anyone show me an example on how do I manipulate the UILabel for iphone, to change every 1min through 100 different words? Obviously you dont have to type out 100 different words but whats the process of code to keep adding words and ot have it change every 1min. Thanks for the help.

Rishil Patel
  • 1,977
  • 3
  • 14
  • 30
BasicApp
  • 23
  • 1
  • 7

2 Answers2

2

I'm not quite sure what you mean by "keep adding words." What you probably want is an NSMutableArray to store the words in. Then use an NSTimer to trigger a method every minute to set the label to a new word.

How to use NSTimer: How do I use NSTimer?

How to use NSMutableArray: http://www.cocoadev.com/index.pl?NSMutableArray

Community
  • 1
  • 1
rob
  • 4,069
  • 3
  • 34
  • 41
  • Sorry for the unclear statement, I ment to ask how do I put into code more words. How do i format a word bank for it to change every 1min into the "something else" – BasicApp Nov 04 '10 at 20:42
0

Set a timer then invalidate it when done.

myTimer = [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(changeLabel) userInfo:nil repeats:YES];

-(void)changeLabel {
    scoreLabel.text = [wordArray objectAtIndex:cntr];
    cntr++;
    if(cntr==100) [myTimer invalidate];
}

This example assumes you have an NSMutableArray or NSArray of 100 words. If you have a growing array of words you could use [wordArray lastObject] to get the last string you added to the mutable array.

Rishil Patel
  • 1,977
  • 3
  • 14
  • 30
Ben
  • 2,982
  • 1
  • 16
  • 12
  • So i assume I keep putting my next word i want to say into "something else" Do i keep copying the changeLabel code for everyword? How do I code all the words into it. – BasicApp Nov 04 '10 at 20:39
  • use the [wordArray lastObject] version of the example I gave and somewhere else in your code do [wordArray addObject:@"Next word"] – Ben Nov 04 '10 at 20:42