首页 > 代码库 > UI:改变UIView背景颜色

UI:改变UIView背景颜色

//每隔一秒改变一次颜色

    [NSTimerscheduledTimerWithTimeInterval:1target:selfselector:@selector(changeColor)userInfo:nilrepeats:YES];



#pragma mark 改变颜色


- (void)changeColor{

    //动画开始

    [UIViewbeginAnimations:nilcontext:nil];

    [UIViewsetAnimationDuration:0.5];

    self.view.backgroundColor = [[UIColoralloc]initWithRed:(double)(arc4random()%256)/256green:(double)(arc4random()%256)/256blue:(double)(arc4random()%256)/256alpha:0.5];

    //动画结束

    [UIViewcommitAnimations];

}


UI:改变UIView背景颜色