UIProgressView doesn't update <=0.5 value after Changing ProgressTintColor

孤街醉人 提交于 2019-12-11 04:18:37

问题


I want to represent a countdown timer. The progress view should change color for <70% - Yellow, <50% -red. But UIProgressView doesn't update after changing ProgressTintColor.(For 0 < x < 0.5).

But It works fine when I comment

[self.progressView setProgressTintColor: [UIColor redColor]]; //this line.

The below code will Trigger for each second:

float value = (float)secondsLeft / (float)secTotalDuration;
if (value < 0.9) {
      if (isChange == NO) {
           //[self.progressView setTranslatesAutoresizingMaskIntoConstraints: NO]; //- I tried THIS.

          [self.progressView setProgressTintColor: [UIColor redColor]]; //LINE - #1
          [self.progressView setTrackTintColor: [UIColor clearColor]];

          isChange = YES;
      }

      dispatch_async(dispatch_get_main_queue(), ^{ //With or without mainqueue doen't affect Uiprogressview change while commenting LINE - #1
                [self.progressView setProgress:value animated:NO];
      });

      NSLog(@"Progress: %f", [self.progressView progress]);

And LOG:

 Progress: 1.000000
 Progress: 0.800000
 Progress: 0.700000
 Progress: 0.500000 //Doesn't updated after this.
 Progress: 0.300000
 Progress: 0.200000

回答1:


Please try this :

-(void) updateProgress:(NSNumber *) value {

       //Progress Value           
         [self.progressView setProgress:value animated:NO];

      //Progress Color        
         if (value < 0.5) {

           [self.progressView setProgressTintColor: [UIColor redColor]];  
           [self.progressView setTrackTintColor: [UIColor clearColor]];   
         }
         else if (value < 0.7) {

          [self.progressView setProgressTintColor: [UIColor yellowColor]];  
          [self.progressView setTrackTintColor: [UIColor clearColor]];
         }
         else if (value < 1.0) {       

          [self.progressView setProgressTintColor: [UIColor greenColor]];  
          [self.progressView setTrackTintColor: [UIColor clearColor]];

         }
}

Then Call it

float value = (float)secondsLeft / (float)secTotalDuration;

[self performSelectorOnMainThread:@selector(updateProgress:) withObject:@(value) waitUntilDone:NO];


来源:https://stackoverflow.com/questions/41339556/uiprogressview-doesnt-update-0-5-value-after-changing-progresstintcolor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!