0

如何让随机文本从 totext1淡出text2

我的代码如下:

 -(IBAction)generateNumbers; {
    int randomNumber = arc4random() % 1;
    switch (randomNumber) {
        case 0:
            label.text = @"text1";
            break;
        case 1:
            label.text = @"text2";
            break;
        default:
            break;
     }
}
4

1 回答 1

2
-(IBAction)generateNumbers; {
int randomNumber = arc4random() % 2;
switch (randomNumber) {
case 0:
    label.text = @"text1";
    break;
case 1:
    label.text = @"text2";
    break;
default:
    break;
 }
}

For fadeIn/Out use this methods

- (void) setTextWithFade {
   [label setAlpha:1];
   [UIView beginAnimations:nil context:nil];
   [UIView setAnimationDuration:1];
   [UIView setAnimationDelegate:self];
   [UIView setAnimationDidStopSelector:@selector(fadeDidStop)];
   [lbl setAlpha:0];
   [UIView commitAnimations];
}

- (void)fadeDidStop {
   label.text = @"new text";
   [UIView beginAnimations:nil context:NULL];
   [UIView setAnimationDuration:1];
   [lbl setAlpha:1];
   [UIView commitAnimations];
}

call the first method when you are click the button like this:

 [self setTextWithFade];
于 2013-04-01T10:06:32.760 回答