LTMorphingLabel
Swift 编写的可以变形的 UILabel 子类。模仿了 WWDC 2014 上苹果的 QuickType 动画效果,如 iOS 8。新的变形效果可以通过 Swift 扩展获得。
枚举 LTMorphingEffect: 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 12
- iOS 9.0+
安装
Swift Package Manager
- 文件 > Swift 包 > 添加包依赖
- 复制并粘贴
https://github.com/lexrus/LTMorphingLabel
然后按照说明操作
XCFramework
XCFramework 是 Xcode 11 中引入的新选项。您可以手动从 发行版页面 下载预编译的 LTMorphingLabel.xcframework.zip,然后将其拖放到项目中。
Carthage
- 将此行添加到 Cartfile:
github "lexrus/LTMorphingLabel"
- 阅读 官方说明
CocoaPods
- 安装 CocoaPods 的最新版本:
gem install cocoapods
- 将此行添加到 Podfile:
pod 'LTMorphingLabel'
- 安装 Pod:
pod install
Accio
- 将以下内容添加到您的 Package.swift 文件中
.package(url: "https://github.com/lexrus/LTMorphingLabel.git", .upToNextMajor(from: "0.9.2")),
- 接下来,将
LTMorphingLabel
添加到您的应用的依赖中,如下所示:
.target(
name: "App",
dependencies: [
"LTMorphingLabel",
]
),
- 然后运行
accio update
。
用法
- 将标签的类从 UILabel 改为 LTMorphingLabel;
- 以编程方式将其文本属性设置为新的字符串。
- 要交互使用,在更改 .text 属性后调用
.pause()
,并使用updateProgress(progress: Float)
来交互式地更新进度。
单元测试
在 Xcode 中打开项目,然后按 command + u。
其他选项
尽管这个库被用于 App Store 中的几个产品,它仍然是一个实验性项目。坦白说,这里还有一些很好的竞争者既能保证兼容性也能保证稳定性。其中最突出的是 ZCAnimatedLabel。我建议对其进行生产使用。
最后,还有一个 Android 端版本。
第三方绑定
React Native
现在您可以通过React Native中的模块这里使用这个库。
许可证
本代码在MIT许可证的条款和条件下分发。