1
我只是想在每次進入由左到右屏幕的時間,使標籤的文字顏色隨機顏色,使用arc4random ..簡單的標籤「屏幕保護程序」幫助需要
下面的代碼適用於1個隨機每次應用程序加載時顏色,但不是當它離開視圖時顏色!
NSTimer* myTimer;
int y = 15;
int x = 0;
-(void)textView
{
myLabel = [[UILabel alloc] initWithFrame :CGRectMake(0, 0, 550, 30)];
myLabel.backgroundColor = [UIColor clearColor];
myLabel.textColor = [UIColor colorWithRed:arc4random()%100/100.0 green:arc4random()%100/100.0 blue:arc4random()%100/100.0 alpha:1];
myLabel.font = [UIFont boldSystemFontOfSize:25];
myLabel.text = @"My Sample Application";
[self.view addSubview:myLabel];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[NSTimer scheduledTimerWithTimeInterval:0.005 target:self selector:@selector(animatedText) userInfo:nil repeats:YES];
[self textView];
[self animatedText];
}
-(void)animatedText
{
if (myLabel.center.x < 640)
{
x += 1;
}
else
{
x = 0;
y =(arc4random() % 500) ;
}
myLabel.center = CGPointMake(x, y);
}
非常感謝你@ ev0lution的快速反應和正確的答案,它的工作! – emotality
沒問題,現在是測試我答案旁邊的「打勾」按鈕的好時機。 ;) – ttarik
+1 @ ev0lution .. – Rajneesh071