• Home
  • About
    • 杜玮的博客 photo

      杜玮的博客

      iOS小开发仔,objective-c、Java、C

    • Learn More
    • Email
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

DWAnimatedLabel

24 Aug 2018

Reading time ~7 minutes

一个UILabel的子类,添加各类型动画,灵感来自RQShineLabel.

wave

中文教程

功能

  • UILabel子类,便于使用
  • 使用 CADisplayLink来展示流畅的动画
  • 四种不同的动画类型
  • 纯Swift语言编写

typewritter

shine

fade

安装

在 Podfile中加入

target 'MyApp' do
  pod 'DWAnimatedLabel', '~> 1.1'
end

然后在终端运行 pod install

另外也可以使用 pod try DWAnimatedLabel 来做一个测试运行

用法

你需要先 import 这个模块

import DWAnimatedLabel

然后像创建普通的 UILabel一样创建这个特殊的 Label

let label = DWAnimatedLabel(frame: CGRect(x: 20, y: 44, width: UIScreen.main.bounds.size.width, height: 100))
label.text = "LOADING"
label.font = UIFont.systemFont(ofSize: 70, weight: .bold)

你可以通过 animationType 属性来选择动画类型

label.animationType = .wave

如果你在使用 wave动画,你还需要设置placeHolderColor 属性来定义底部颜色,否则他会使用 UIColor.lightGray作为背景色。

label.placeHolderColor = .blue

设置完成后你可以使用 startAnimation(duration: TimeInterval, _ completion:(() -> Void)?) 来展示动画

Requirements

  • iOS 9.0 +
  • Swift 4
  • Xcode 9

Contribution

欢迎对项目提供宝贵意见,有问题也可以在Github Issue上与我进行联系

License

DWAnimatedLabel is open-sourced software lincened under the MIT license.

Credits

有兴趣可以关注我的博客,里面有更多内容



iOS开发Github Share Tweet +1