SKAutoScrollLabel
具有水平和垂直滚动条效果的自动滚动UILabel,边缘具有渐变效果。使用边缘渐变解决了滚动边框的硬边缘问题。整体效果自然且易于使用。
特性
- 支持向上、向下、向左和向右四个方向的自动滚动。
- 可自由控制滚动的暂停/继续。
- 在应用背景切换时,滚动行为不会被中断。
- 轻量级,至少需要一行初始化代码来创建。
- 渐变效果更柔和、更自然。
- 代码已全部注释,并提供使用说明。
使用效果
使用方法
第1步:执行git clone [email protected]:shevakuilin/SKAutoScrollLabel.git
,然后查看Example
。
第2步:将文件夹中的SKAutoScrollLabel
直接复制到您的项目中,或者将pod 'SKAutoScrollLabel'
添加到Podfile中。
第3步:引用头文件#import <SKAutoScrollLabel/SKAutoScrollLabel.h>
安装
由代码创建
// Scroll from right to left
SKAutoScrollLabel *scrollLabel = [[SKAutoScrollLabel alloc] initWithTextContent:@"Fly me to the moon.Let me play among the stars.Let me see what spring is like on Jupiter and Mars.In other words, hold my hand.In other words, baby, kiss me." direction: SK_AUTOSCROLL_DIRECTION_LEFT];
scrollLabel.backgroundColor = [UIColor orangeColor];
scrollLabel.textColor = [UIColor whiteColor];
// ... other settings
由Storyboard创建
// Set the object's class to SKAutoScrollLabel in the storyboard
@property (weak, nonatomic) IBOutlet SKAutoScrollLabel *scrollLabel;
// Scroll from right to left
self.scrollLabel.textContent = @"Fly me to the moon.Let me play among the stars.Let me see what spring is like on Jupiter and Mars.In other words, hold my hand.In other words, baby, kiss me.";
self.scrollLabel.direction = SK_AUTOSCROLL_DIRECTION_LEFT;
self.scrollLabel.backgroundColor = [UIColor orangeColor];
self.scrollLabel.textColor = [UIColor whiteColor];
// ... other settings
参数含义
-
direction
滚动方向- SK_AUTOSCROLL_DIRECTION_RIGHT // 从左到右滚动
- SK_AUTOSCROLL_DIRECTION_LEFT // 从右到左滚动
- SK_AUTOSCROLL_DIRECTION_TOP // 从下到上滚动
- SK_AUTOSCROLL_DIRECTION_BOTTOM // 从上到下滚动
-
pointsPerFrame
每帧移动的距离。默认值为1.0f。 -
labelSpacing
滚动标签之间的间距。默认值为20。 -
textContent
纯文本内容。 -
attributedTextContent
富文本内容。 -
textColor
纯文本颜色。 -
font
纯文本字体。 -
textAlignment
纯文本对齐方式。 -
enableFade
默认YES。启用标签边界的渐变褪色。
控制方法
- (void)pauseScroll; // Pause scrolling animation being played.
- (void)continueScroll; // Make a paused scrolling animation continue playing.
简述
SKAutoScrollLabel是一个同时支持水平和垂直两种类型的“跑马灯”效果的自动滚动UILabel。在滚动的边缘使用了梯度褪色来解决滚动边缘生硬的效果问题,总体效果呈现出混然天成的感觉,并且使用简单方便。如果你觉得还不错,请star支持一下吧~
特性
- 支持上、下、左、右四个方向的自动滚动
- 随时可自由控制的滚动暂停 / 继续
- 应用前后台切换时,滚动行为不会被中断
- 轻量级,最少仅需一行初始化代码即可完成创建
- 控件梯度渐变效果柔和,更自然
- 完善的文档和说明
效果图
如何开始
1.git clone [email protected]:shevakuilin/SKAutoScrollLabel.git
,查看示例工程 Example
2.直接将目录下的 SKAutoScrollLabel 拷贝到你的工程中,或在Podfile文件中添加 pod 'SKAutoScrollLabel'
3.引用头文件 #import <SKAutoScrollLabel/SKAutoScrollLabel.h>
初始化
通过代码创建
// 创建一个从右向左滚动的,背景颜色为橙色,字体颜色为白色的滚动 Label
SKAutoScrollLabel *scrollLabel = [[SKAutoScrollLabel alloc] initWithTextContent:@"你指尖跃动的电光, 是我此生不灭的信仰! 唯我超电磁炮永世长存!! 哔哩哔哩(゜-゜)つロ干杯~-bilibili" direction: SK_AUTOSCROLL_DIRECTION_LEFT];
scrollLabel.backgroundColor = [UIColor orangeColor];
scrollLabel.textColor = [UIColor whiteColor];
// ... 其他设置
通过 storyboard 创建
// 在 storyboard 中将对象的类设置为 SKAutoScrollLabel
@property (weak, nonatomic) IBOutlet SKAutoScrollLabel *scrollLabel;
// 创建一个从右向左滚动的,背景颜色为橙色,字体颜色为白色的滚动 Label
self.scrollLabel.textContent = @"你指尖跃动的电光, 是我此生不灭的信仰! 唯我超电磁炮永世长存!! 哔哩哔哩(゜-゜)つロ干杯~-bilibili";
self.scrollLabel.direction = SK_AUTOSCROLL_DIRECTION_LEFT;
self.scrollLabel.backgroundColor = [UIColor orangeColor];
self.scrollLabel.textColor = [UIColor whiteColor];
// ... 其他设置
基本参数
-
direction
滚动方向- SK_AUTOSCROLL_DIRECTION_RIGHT // 从左向右滚动, 默认选项
- SK_AUTOSCROLL_DIRECTION_LEFT // 从右向左滚动
- SK_AUTOSCROLL_DIRECTION_TOP // 从下向上滚动
- SK_AUTOSCROLL_DIRECTION_BOTTOM // 从上向下滚动
-
pointsPerFrame
每帧移动的距离。默认值为1.0f。 -
labelSpacing
每个滚动标签的间距。默认值为20。 -
textContent
普通文本内容 -
attributedTextContent
富文本内容 -
textColor
文本颜色 -
font
字体 -
textAlignment
文字对齐 -
enableFade
开启/关闭渐变效果,默认开启
控制方法
- (void)pauseScroll; // 暂停滚动
- (void)continueScroll; // 继续滚动
感谢您花时间阅读以上内容,如果您觉得这个项目对您有帮助,请告诉我。
Email: [email protected]