[英]Animate UILabel text
I'm new to iOS programming and i've got a question: I want to make a kind of custom progress bar. 我是iOS编程的新手,我有一个问题:我想制作一种自定义进度条。 I've created 2
UIView
s, one above the other and animated the front UIView
with this code: 我创建了2个
UIView
,一个在另一个之上,用这段代码为前面的UIView
制作动画:
[UIView animateWithDuration:1.5f delay:1.0f options:UIViewAnimationOptionCurveEaseInOut animations:^{
[barCima setFrame:CGRectMake(10, 300, value, 30)];
}
completion:nil];
But now, I would like to do something more. 但现在,我想做更多的事情。 I want that while the width bar is growing, a
UILabel
appears with the current value. 我希望在宽度条增长时,
UILabel
显示当前值。 Example: I set de value
to 300. While the animation is occurring, the UILabel
is showing the progress until it reaches the 300 (1, 2, 3, 4, 5, 6, 7,...,300). 示例:我将de
value
设置为300.在动画发生时, UILabel
显示进度,直到达到300(1,2,3,4,5,6,7,...,300)。
You need an NSTimer
that fires every one second or so, and a counter. 你需要每隔一秒左右触发的
NSTimer
和一个计数器。 Whenever the NSTimer
fires, the counter is incremented, and UILabel
's text will be updated. 每当
NSTimer
触发时,计数器都会递增, UILabel
的文本将被更新。 It should look like this 它看起来应该是这样的
int _counter; // An instance var
self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerFired) userInfo:nil repeats: YES];
// Be sure you call [self.timer invalidate] when you don't need it anymore
...
-(void)timerFired {
++ _counter;
self.label.text = [NSString stringWithFormat:@"%i", _counter];
}
Good luck thought I don't know what you use such a progress bar for! 祝你好运,以为我不知道你用的是什么进步吧!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.