小技巧----随机背景颜色

#define COLOR_VALUE arc4random() % 256 /255.0//宏定义

@interface FirstViewController ()
{
    NSTimer *_timer;
}//定义一个事件的属性

[self createBackCorlor];//方法的调用

#pragma mark - 定时器方法
- (void)createBackCorlor
{
    _timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
}

#pragma mark - 定时器方法
- (void)onTimer
{
    self.view.backgroundColor = [UIColor colorWithRed:COLOR_VALUE green:COLOR_VALUE blue:COLOR_VALUE alpha:1];
}

 

以上做的是让self背景颜色每0.5秒随机变换

posted @ 2015-09-25 20:49  阿凡提王  阅读(282)  评论(0编辑  收藏  举报