如何动画UILabel字体更改?

时间:2012-11-01 15:03:40

标签: ios animation label

我正在创建一个字体大小为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) {

 }];

谢谢!

1 个答案:

答案 0 :(得分:0)

[UIView beginAnimations:nil context:nil];
label.transform = CGAffineTransformMakeScale(0.5,0.5);
[UIView commitAnimations];

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