ThenMorphingLabel
是从 LTMorphingLabel 分支出来的。
Swift 编写的 morphing UILabel 子类。.Scale 效果模仿了 Apple's QuickType animation of iOS 8 of WWDC 2014。还包括作为 Swift 扩展的新 morphing 效果。
enum ThenMorphingLabel.Effect: Int, Printable
.Scale - 默认
.Evaporate
.Fall
.Pixelate
.Sparkle
.Sparkle 是在 QuartzCore.CAEmitterLayer 的基础上构建的。还有一个基于 SpriteKit 的版本,请参阅 此处。
.Burn
.Anvil
SwiftUI
public var body: some View {
VStack {
MorphingText(
"Awesome Morphing Text",
effect: .evaporate,
font: UIFont.systemFont(ofSize: 20),
textColor: .black,
textAlignment: .center
).frame(maxWidth: 200, maxHeight: 100)
...
需求
- iOS 11.0+
安装
Swift 包管理器
- 文件 > Swift 包 > 添加包依赖
- 复制并粘贴
https://github.com/ghostcrying/ThenMorphingLabel
,然后按照指示操作
Carthage
- 将此行添加到您的 Cartfile 中:
github "ghostcrying/ThenMorphingLabel"
- 阅读官方说明
CocoaPods
- 安装 CocoaPods 的最新版本:
gem install cocoapods
- 将此行添加到您的 Podfile 中:
pod 'LTMorphingLabel'
- 安装 pod:
pod install
用法
- 将 label 的类从 UILabel 改为 LTMorphingLabel;
- 通过代码设置一个新的 String 到它的 text 属性。
- 要交互式地使用,在更改
.text
属性后调用.pause()
,并使用updateProgress(progress: Float)
交互式地更新进度。