我使用NSTimer进行了45秒倒计时,如下所示:
-(IBAction)Start {
mainInt = 45;
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(countDown) userInfo:nil repeats:YES]; }
- (void)countDown {
mainInt -= 1;
seconds.text = [NSString stringWithFormat:@"%i", mainInt];
if (mainInt == 0) {
[timer invalidate];
}
然后我在我的故事板中放置了一个简单的UIProgressView。我尝试在没有代码的情况下将它们连接在一起,但它显然并不那么容易。如何将UIProgressView链接到NSTimer以确保倒计时达到0后进度条是否已满?
答案 0 :(得分:1)
您可以从UIProgressView
NSTimer
- (void)countDown
{
mainInt -= 1;
seconds.text = [NSString stringWithFormat:@"%i", mainInt];
yourProgressView.progress = (45 - mainInt)/45.0f;
if (mainInt == 0)
{
[timer invalidate];
}
}