Blinking effect on UILabel

前端 未结 14 1981
野的像风
野的像风 2020-12-13 14:24

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

14条回答
  •  青春惊慌失措
    2020-12-13 14:45

    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;
       }
    }
    

提交回复
热议问题