ios - 动画 UILabel 文本

标签 ios jquery-animate uilabel progress

我是 iOS 编程的新手,我有一个问题: 我想制作一种自定义进度条。我创建了 2 个 UIView,一个在另一个之上,并使用以下代码为前面的 UIView 设置动画:

[UIView animateWithDuration:1.5f delay:1.0f options:UIViewAnimationOptionCurveEaseInOut animations:^{
       [barCima setFrame:CGRectMake(10, 300, value, 30)];
    }
                     completion:nil];

但是现在,我想做更多的事情。我希望当宽度条增长时,UILabel 会出现当前值。示例:我将 de value 设置为 300。在动画发生时,UILabel 显示进度,直到达到 300(1、2、3、4、5 , 6, 7,...,300).

最佳答案

您需要一个每隔一秒左右触发一次的 NSTimer 和一个计数器。每当 NSTimer 触发时,计数器就会增加,UILabel 的文本也会更新。它应该是这样的

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];
}

祝你好运,我不知道你用这样的进度条干什么!

关于ios - 动画 UILabel 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17261354/

相关文章:

ios - 标题部分加粗,iOS 7

ios - AKNodeOutputPlot 提高速度吗?

ios - 如何在没有按钮的情况下关闭 UIAlertController

ios - 在 UILabel 中显示 2 行半行文本

ios - 如何找到 UILabel 的现有 UIFontTextStyle?

ios - DBAccess 创建自定义 DBAccessSettings

jQuery 插件可以在不反转内容的情况下执行旋转/翻转动画?

JQuery 背景动画 - 这是正确的方法吗?

javascript - 我的 div 使用 show() 正确淡入,但在动画完成后它会跳起来

ios - adjustsFontSizeToFitWidth 在 iOS 14 上与 NSMutableAttributedString 无法正常工作