一个执行真实文本属性动画的 UILabel
。
它动画化所有可能的文本属性,而不仅仅是 CATextLayer
动画字体和颜色。
它还提供了多行文本动画的强大支持,同时几乎保留了所有 UILabel
的优点。
它使用 CoreText 文本渲染而不是 CATextLayer
的 CoreGraphics 文本渲染。这使得文本的 advancement 和 行高与常规 UILabel
中的文本相同。
它是实现材料设计 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采用简化版BSD许可协议发布。有关详情,请参见LICENSE。