Search code examples
iosobjective-ccocoa-touchuiviewuilabel

Blinking effect on UILabel


I have a UILabel with background color as grey.

I want a blinking effect on this label like it should become a little white & then become gray and it should keep happen till I turn it off programatically.

Any clue how to achieve this?


Solution

  • Use NSTimer

    NSTimer *timer = [NSTimer 
                          scheduledTimerWithTimeInterval:(NSTimeInterval)(1.0)
                                target:self 
                                 selector:@selector(blink) 
                                 userInfo:nil 
                                 repeats:TRUE];
    BOOL blinkStatus = NO;
    

    in your blink function

    -(void)blink{
       if(blinkStatus == NO){
          yourLabel.backgroundColor = [UIColor whiteColor];
         blinkStatus = YES;
       }else {
          yourLabel.backgroundColor = [UIColor grayColor];
          blinkStatus = NO;
       }
    }