UIColor *_color[5] UIColor数组

黎震博
2023-12-01

#import "ViewController.h"


@interface ViewController (){

    

    

    UIColor *_color[5];

}


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    

    

    _color[0] = [UIColor redColor];

    _color[1] = [UIColor blueColor];

    _color[2] = [UIColor greenColor];

    _color[3] = [UIColor cyanColor];

    _color[4] = [UIColor yellowColor];

    

    

    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(change) userInfo:nil repeats:YES];

    

    [timer fire];

    

    

}



- (void)change{

    

    int x = arc4random() % 5;


    

    self.view.backgroundColor = _color[x];

    

}




@end

 类似资料: