一个能够对富文本进行真正动画的 UILabel
。
与仅能动画字体和颜色的 CATextLayer
不同,它能够动画所有可以动画的文本属性。
它对多行文本动画有很好的支持,同时几乎保留了作为 UILabel
的所有优点。
它使用 CoreText 文本渲染,而不是 CATextLayer
的 CoreGraphics 文本渲染。这使得文本在排版和行高上与常规 UILabel
中的文本看起来相同。
它是实现 Material Design 的 UI 的一个很棒且简单的构建块。
安装 >> 说明
<<
您可以使用 LKLabel
或 LKLabelLayer
,两者都支持隐式可动画的文本更改。 当图层由 LKLabel
托管时,边界更改期间的文本动画更稳定。
在 LKLabel
中动画文本更改可以是这样的
// 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];
在 LKLabelLayer
中动画文本更改可以是这样的
// 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];
请参阅
文档
以获得可能性的详细描述。
LabelKit 在 Simplified BSD 许可证下发布。 有关详细信息,请参见 LICENSE。