屏幕颜色闪烁

@implementation AppDelegate

- (void)dealloc

{

    [_window release];

    [super dealloc];

}

NSInteger a = 5;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    [_window release];

    view = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];

    view.backgroundColor = [UIColor yellowColor];

    [self.window addSubview:view];

    view.center = self.window.center;

    //(定时器)

    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(change1) userInfo:nil repeats:YES];

    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(changeColor) userInfo:nil repeats:YES];

    [view release];

    lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];

    lable.backgroundColor = [UIColor redColor];

   

    [view addSubview:lable];

    lable.center = view.center;

    lable.layer.borderColor = [UIColor blackColor].CGColor;

    lable.layer.borderWidth = 2;

    lable.layer.cornerRadius = 10;

    lable.layer.masksToBounds = YES;

    [lable release];

    return YES;

}

- (void)change1

{

    if (a > 0) {

        NSString *str = [NSString stringWithFormat:@"%ld", a];

        lable.text = str;

        lable.font = [UIFont boldSystemFontOfSize:40.0];

        lable.textAlignment = NSTextAlignmentCenter;

    }

    if (a == 0) {

        lable.text = @"闪瞎你";

        lable.font = [UIFont boldSystemFontOfSize:30.0];

        lable.textAlignment = NSTextAlignmentCenter;

        lable.textColor = [UIColor blueColor];

    }

    a--;

    }

- (void)changeColor

{if (a < 0){

    view.backgroundColor = [UIColor redColor];

    int a = arc4random()%(255 + 1);

    int b = arc4random()%(255 + 1);

    int c = arc4random()%(255 + 1);

    view.backgroundColor = [UIColor colorWithRed:a/255.0 green:b/255.0 blue:c/255.0 alpha:1];}

}


你可能感兴趣的:(颜色,屏幕,闪烁)