I need a way to change UILabel's font with an animation. I saw many ways to animate changes in font size but I need a way to change it's type (bold ti thin for example).
This might be helpful to people who search this answer:
To fade from one font to another do this:
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 different font)
There's no discrete mapping (in the mathematical sense) between two font faces.
If you can go from size 10 to size 11 by ramping (10.1, 10.2, 10.3, ...) there's no such thing as "something 45% between helvetica neue and helvetica neue bold".
The closest you could do is morph between the CGPaths of the individual letters, but that'd involve a huge work with CoreText.
Meanwhile, I just advise you to perform a simple crossfade.
Maybe in the future (wink, wink) there will be some frameworks to help you with this kind of task.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With