LabelKit

2.0.0

A UILabel that does true animation of attributed text.
edudnyk/LabelKit

What's New

SwiftUI bridging and fixes

2021-01-15T22:17:57Z
  • Added animation bridging from SwiftUI with LabelView.
  • Removed broken support of layoutMargins in LKLabel.
  • Added support of optimised text rendering when label.numberOfLines == 1.
  • Added respecting of the default font of LKLabel.

LabelKit

build status cocoapods compatible carthage compatible language swift

A UILabel that does true animation of attributed text.

It animates all text attributes that are possible to animate, unlike CATextLayer that animates only font and color.

It also has a great support of multiline text animations while keeping almost all the benefits of being UILabel.

It uses CoreText text rendering instead of CoreGraphics text rendering of CATextLayer. That makes the text to look the same by advancement and line height as the text in regular UILabel.

It is a great and simple building block for UI which implements material design.

Features

Requirements

xcode ios tvos mac os

Installation >> instructions <<

Usage

You can use either LKLabel or LKLabelLayer, both support implicitly animatable text change. When the layer is hosted by LKLabel, animations of text during bounds change are more stable.

Animating text change in LKLabel can be something like this:

// Swift
self.label.superview.setNeedsLayout()
self.label.setNeedsLayout()
UIView.animate(withDuration: 3, delay: 0, options: [], animations: {
    self.label.attributedText = attributedText
    self.label.superview.layoutIfNeeded()
}, completion: nil)
// Objective-C
[self.label.superview setNeedsLayout];
[self.label setNeedsLayout];
[UIView animateWithDuration:3 delay:0 options:kNilOptions animations:^{
    self.label.attributedText = attributedText;
    [self.label.superview layoutIfNeeded];
} completion:nil];

Animating text change in LKLabelLayer can be something like this:

// Swift
CATransaction.begin()
CATransaction.setAnimationDuration(3.0)
labelLayer.attributedText = attributedText
CATransaction.commit()
// Objective-C
[CATransaction begin];
[CATransaction setAnimationDuration:3.0];
labelLayer.attributedText = attributedText;
[CATransaction commit];

Refer to the documentation for the detailed description of possibilities.

License

LabelKit is released under the Simplified BSD license. See LICENSE for details.

Description

  • Swift Tools 5.0.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu Nov 07 2024 09:16:15 GMT-1000 (Hawaii-Aleutian Standard Time)