JZRollableLabel-Swift 5.0.3

JZRollableLabel-Swift 5.0.3

Jiahao Zhu 维护。



  • 朱嘉皓

JZRollableLabel

JZRollableLabel 是一种在显示信息时可以进行滚动的标签控件。

CI Status Version License Platform

⚠️ 使用 Swift 4.x 时,请确保您使用 >= 4.0.0 ⚠️

⚠️ 使用 Swift 5.x 时,请确保您使用 >= 5.0.0 ⚠️

内容

更新

新功能

  • 目前支持 'numberOfLines' 属性。
  • 滚动核心已与外部壳分离,因此现在没有暴露的函数不应被调用。
  • 由于上述相同原因,为 JZRollableLabel 的子类实现 CAAnimationDelegate 的限制不再存在。

错误已修复

  • 内置内容大小逻辑现在已修复。
  • 未指定高度时的布局问题现在已修复。

示例

要运行示例项目,克隆仓库,然后从Example目录运行pod install

需求

  • 最低iOS目标版本:9.0。
  • Swift版本:4.0以上。

安装

CocoaPods

CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装它

$ gem install cocoapods

要使用 CocoaPods 集成 JZRollableLabel,请在您的 Podfile 中指定它

/* For project that is using Swift 4.x */
pod 'JZRollableLabel', '~> 4.0.0'

/* For project that is using Swift 5.x */
pod 'JZRollableLabel', '~> 5.0.0'

然后,运行以下命令

$ pod install

手动

当然,如果您喜欢,您也可以手动将 SnapKit 集成到项目中!😊

用法

JZRollableLabel 可以通过以下代码轻松创建和使用

import JZRollableLabel_Swift

let label = JZRollableLabel(/*frame: <any CGRect>*/)
view.addSubview(label)
/* Any additional operations to layout the label.
	 The layout feature of this label is designed to the same as UILabel. */

可以通过调用函数 'beginRolling()' 开始滚动动画

label.beginRolling()
/* This function can be called anytime,
	 but calling it too early will case unexpected changes of its status due to layouting. */

可以通过调用函数 'stopRolling(immediately: Bool)' 停止滚动动画

/* Passing different values will cause the different in wyas to terminate the animation. */

label.stopRolling(immediately: true)
/* This will stop the animation immediately. */

label.stopRolling(immediately: true)
/* This will stop the animation after the current round of animation completes. */

JZRollableLabel 的属性在任何时候都是可变的,但更改它们将重新启动动画的开始,因此如果您想更改得更平滑或者动画当前圆之后,可以使用代理并查找函数 'rollingDidStop(finished flag: Bool)'。它可以以下方式使用

extension /* The class of any object you want to use as the delegate */: JZRollableLabelDelegate {
    
  	/* This is called when the animation has stopped. */
    func rollingDidStop(finished flag: Bool) {
        if flag {
						/* This is the situation while the animation goes to the end. */
        } else {
						/* This is the situation while the animation being interrupted by any other operation. */
        }
    }
    
  	/* This is called when the animation has began. */
    func rollingDidStart() {
      	
    }
    
}

属性和方法

以下是 JZRollableLabel 独有的属性列表

属性 访问权限 描述
spacing 读写 首尾动画标签之间的最小间距。
direction 读写 滚动动画的方向。
style 读写 动画样式。
speed 读写 动画速度,默认值为 1,表示每 10 秒 1 屏幕宽。
duration 只读 动画持续时间。
gap 读写 动画两轮之间的时间间隔。
delegate 读写 充当滚动标签代理的对象。
status 只读 滚动动画的当前状态,只读。

以下是支持的 UILabel 属性

属性 访问权限 描述
text 读写 标签显示的文本。
font 读写 显示文本所使用的字体。
textColor 读写 文本的颜色。
shadowColor 读写 文本的阴影颜色。
shadowOffset 读写 文本的阴影偏移量(用点数衡量)。
textAlignment 读写 用于对齐文本的技术。
lineBreakMode 读写 用于换行和截断标签文本的技术。
attributedText 读写 标签显示的样式化文本。
highlightedTextColor 读写 标签文本的突出显示颜色。
isHighlighted 读写 一个布尔值,用于确定标签是否以突出显示绘制其文本。
isEnabled 读写 一个布尔值,用于确定标签是否以启用状态绘制其文本。
numberOfLines 读写 渲染文本的最大行数。

为 JZRollableLabel 实现的特殊功能如下

功能 描述 注意
beginRolling() 开始滚动的函数。 可以在布局控件之前调用此函数,但状态可能多次更改,出人意料。
stopRolling(immediately: Bool) 终止滚动的函数。 如果动画已经结束,状态不会改变为 "停止"。

作者

朱嘉皓, [email protected]

许可证

JZRollableLabel 允许使用 MIT 许可协议。详细信息请查阅 LICENSE 文件。