iOS 实现UILabel的跑马灯效果

本文介绍如何在iOS应用中实现UILabel的跑马灯效果。通过使用自定义的UIScrollView,当文字超出UILabel显示范围时,内容会自动滚动。提供了一个GitHub项目链接,并详细说明了配置选项,如滚动方向、速度和暂停时间。
摘要由CSDN通过智能技术生成

github地址:点击打开链接

项目新功能模块UILabel长度有限,想要完全看到字就需要有跑马灯效果。

于是众里寻他千百度·······此处使用的是自定义的UIScrollView···

点击进入原文

效果图


代码

AutoScrollLabel.h

#import <UIKit/UIKit.h>

#define NUM_LABELS 2

enum AutoScrollDirection {
	AUTOSCROLL_SCROLL_RIGHT,
	AUTOSCROLL_SCROLL_LEFT,
};

@interface AutoScrollLabel : UIScrollView <UIScrollViewDelegate>{
	UILabel *label[NUM_LABELS];
	enum AutoScrollDirection scrollDirection;
	float scrollSpeed;
	NSTimeInterval pauseInterval;
	int bufferSpaceBetweenLabels;
	bool isScrolling;
}
@property(nonatomic) enum AutoScrollDirection scrollDirection;
@property(nonatomic) float scrollSpeed;
@property(nonatomic) NSTimeInterval pauseInterval;
@property(nonatomic) int bufferSpaceBetweenLabels;
// normal UILabel properties
@property(nonatomic,retain) UIColor *textColor;
@property(nonatomic, retain) UIFont *font;

- (void) readjustLabels;
- (void) setText: (NSString *) text;
- (NSString *) text;
- (void) scroll;


@end

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值