UILabel Change Animation Font

I need a way to change the UILabel font with animation. I have seen many ways to animate font size changes, but I need a way to change its type (for example, bold).

+8
source share
5 answers

There is no discrete mapping (in the mathematical sense) between two faces of a font.

If you can go from size 10 to size 11 by building (10.1, 10.2, 10.3, ...), there is no such thing as "something 45% between helvetica neue and helvetica neue bold".

The closest thing you can do is convert between the CGPaths of the individual letters, but this will require a lot of work with CoreText.

Meanwhile, I just advise you to do a simple crossfade.

Maybe in the future (wink, wink) there will be some framework that will help you in this task.

+12
source

This may be useful for people looking for this answer:

To switch from one font to another, do the following:

UIView.transition(with: label, duration: 0.25, options: .transitionCrossDissolve, animations: { self.label.font = UIFont.systemFont(ofSize: 15) }) { isFinished in } 

when there is text, go to:

 UIView.transition(with: label, duration: 0.25, options: .transitionCrossDissolve, animations: { self.label.font = UIFont.boldSystemFont(ofSize: 15) }) { isFinished in } 

(Gif shows a different font)

enter image description here

+1
source

You can set a new size and make changes to your shortcut after the animation as follows.

 [UIView animateWithDuration:0.9 animations:^{ label.frame = (CGRect){ CGPointMake(51, 150), label.bounds.size }; } completion:^(BOOL finished) { label.font=[UIFont boldSystemFontOfSize:15]; // etc. }]; 

Enjoy !!

0
source

Use uiview animateWithDuration. Inside the block, change the font type (bold)

-one
source
 if(font_index == 8) font_index = 0; [UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{ UIFont* newfont = Nil; if(font_index % 2 != 0) { newfont = [UIFont fontWithName:self.fontNames[font_index] size:8]; } else { newfont = [UIFont fontWithName:self.fontNames[font_index] size:20]; } self.keyButton.titleLabel.font = newfont; } completion:^(BOOL finished){ // if(finished) // { font_index++; [self fontIt]; //} }]; 

}

This code may answer your question.

-2
source

All Articles