【问题标题】:How to animate UILabel font change?如何为 UILabel 字体更改设置动画?
【发布时间】:2012-11-01 15:03:40
【问题描述】:

我正在创建一个字体大小为 0 的标签,我想放大它,同时让它消失。 一件重要的事情是我想调整标签大小和位置到中心和视图(它可以是 iphone 或 ipad)。 在我的代码中,我必须从大字体开始,有其他建议吗?

我的代码:

UILabel* swipeLabel = [[UILabel alloc] initWithFrame:self.view.frame];
[swipeLabel setText:NSLocalizedString(@"Swipe to change", @"Swipe label text")];
[swipeLabel setTextColor:[UIColor whiteColor]];
[swipeLabel setTextAlignment:UITextAlignmentCenter];
[swipeLabel setFont:[UIFont systemFontOfSize:2]];
[swipeLabel setAdjustsFontSizeToFitWidth:YES];
[swipeLabel setBackgroundColor:[UIColor clearColor]];
[swipeLabel setNumberOfLines:1];

[self.view addSubview:swipeLabel];


[UIView animateWithDuration:1.5 delay:0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
     CGFloat scaleFactor = 10.0f;
     swipeLabel.transform = CGAffineTransformMakeScale(scaleFactor, scaleFactor);
    [swipeLabel setAlpha:0];
 } completion:^(BOOL finished) {

 }];

谢谢!

【问题讨论】:

标签: ios animation label


【解决方案1】:
[UIView beginAnimations:nil context:nil];
label.transform = CGAffineTransformMakeScale(0.5,0.5);
[UIView commitAnimations];

这将使字体 %50 的大小变小。

【讨论】:

  • @user1553961 所以制作 CGAffineTransformMakeScale(1.5,1.5);例如。
  • @user1553961 你的意思是它越来越小而不是越来越大?还是什么都没有?
猜你喜欢
  • 2013-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-26
  • 1970-01-01
相关资源
最近更新 更多