-(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];
更改這一個int randomNumber = arc4random()%2; – Balu
如果你有10個數字你想要1到10,'使用arc4random()%10 + 1'。如果你有數組,然後使用'arc4random()%array.count' –