我想代表一个倒数计时器。进度视图应更改<70% - 黄色,<50%-red的颜色。但是在更改ProgressTintColor后UIProgressView
不会更新。(对于0&lt; x&lt; 0.5)。
但是当我评论
时它工作正常[self.progressView setProgressTintColor: [UIColor redColor]]; //this line.
以下代码将每秒触发:
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]);
和日志:
Progress: 1.000000
Progress: 0.800000
Progress: 0.700000
Progress: 0.500000 //Doesn't updated after this.
Progress: 0.300000
Progress: 0.200000
答案 0 :(得分:0)
请试试这个:
-(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]];
}
}
然后调用它
float value = (float)secondsLeft / (float)secTotalDuration;
[self performSelectorOnMainThread:@selector(updateProgress:) withObject:@(value) waitUntilDone:NO];