繁体   English   中英

如何制作UILabel字体更改的动画?

[英]How to animate UILabel font change?

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

 }];

谢谢!

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM