Blinking effect on UILabel

前端 未结 14 1834
野的像风
野的像风 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 15:03
        int count;
        NSTimer *timer;
    
          timer= [NSTimer
                      scheduledTimerWithTimeInterval:(NSTimeInterval)(0.5)
                      target:self
                      selector:@selector(animationStart)
                      userInfo:nil
                      repeats:TRUE];
    
    -(void)animationStart{
    switch (count) {
        case 0:
            //205   198 115
            count++;
            lbl.textColor=[UIColor colorWithRed:205.0f/255.0f green:198.0f/255.0f blue:115.0f/255.0f alpha:1];
    
            break;
        case 1:
             count++;
            //205   198 115 56  142 142
            lbl.textColor=[UIColor colorWithRed:56.0f/255.0f green:142.0f/255.0f blue:142.0f/255.0f alpha:1];
    
            break;
        case 2:
             count++;
            //205   198 115
            lbl.textColor=[UIColor colorWithRed:205.0f/255.0f green:205.0f/255.0f blue:0.0f/255.0f alpha:1];
    
            break;
        case 3:
             count++;
            //205   198 115 84  255 159
            lbl.textColor=[UIColor colorWithRed:84.0f/255.0f green:255.0f/255.0f blue:159.0f/255.0f alpha:1];
    
            break;
        case 4:
             count++;
            //205   198 115 255 193 37
            lbl.textColor=[UIColor colorWithRed:255.0f/255.0f green:193.0f/255.0f blue:37.0f/255.0f alpha:1];
    
            break;
        case 5:
             count++;
            //205   198 115 205 200 177
            lbl.textColor=[UIColor colorWithRed:205.0f/255.0f green:200.0f/255.0f blue:117.0f/255.0f alpha:1];
    
            break;
        case 6:
             count++;
            //205   198 115 255 228 181
            lbl.textColor=[UIColor colorWithRed:255.0f/255.0f green:228.0f/255.0f blue:181.0f/255.0f alpha:1];
    
            break;
        case 7:
             count++;
            //205   198 115 233 150 122
            lbl.textColor=[UIColor colorWithRed:233.0f/255.0f green:150.0f/255.0f blue:122.0f/255.0f alpha:1];
    
            break;
        case 8:
            count++;
            //205   198 115 233 150 122
            lbl.textColor=[UIColor colorWithRed:255.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1];
    
            break;
        case 9:
             count=0;
            //205   198 115 255 99  71 255  48  48
            lbl.textColor=[UIColor colorWithRed:255.0f/255.0f green:48.0f/255.0f blue:48.0f/255.0f alpha:1];
    
            break;
    
        default:
            break;
    }
    

    }

    0 讨论(0)
  • 2020-12-13 15:06

    You can do this within a block:

    self.yourLabel.alpha = 1;
    [UIView animateWithDuration:1.5 delay:0.5 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{
            self.yourLabel.alpha = 0;
    } completion:nil];
    

    So you dont need a second method.

    0 讨论(0)
提交回复
热议问题