簡體   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