随机文字淡出

时间:2013-04-01 09:59:55

标签: text random ios6 fading

如何将随机文字从text1转移到text2

我的代码如下:

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

1 个答案:

答案 0 :(得分:2)

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

对于淡入/淡出使用此方法

- (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];
}
当你点击这样的按钮时,

调用第一个方法:

 [self setTextWithFade];