首页 > 其他 > 详细

实现Label中文字的滚动(跑马灯形式)

时间:2015-11-19 11:05:08      阅读:239      评论:0      收藏:0      [点我收藏+]

//这是LabelTest.m 文件

#import "LabelTest.h"


@interface LabelTest ()
@property(nonatomic,strong)MarqueeLabel *lab;

@end

@implementation LabelTest

- (void)viewDidLoad {
    [super viewDidLoad];
 
   _lab=[[MarqueeLabel alloc] init];
    _lab.frame=CGRectMake(100, 300, 200, 30);
    _lab.backgroundColor=[UIColor yellowColor];
    _lab.text=@"This is a long string, that‘s also an attributed string, which works just as well!";
    //文字滚动的类型
    //首尾相连(从左到右)
    _lab.marqueeType = MLContinuous;
    //文字开始滚动时很快,到最后会变慢,可以点进去看类型
    _lab.animationCurve = UIViewAnimationOptionCurveEaseOut;

    //从首到尾 在从尾到首循环
//    _lab.marqueeType = MLLeftRight;

    //首尾相连(从右到做左)
//   _lab.marqueeType = MLContinuousReverse;

    
    //暂停按钮
    UIButton *btn=[UIButton buttonWithType:(UIButtonTypeCustom)];
    btn.frame=CGRectMake(50, 200, 100, 30);
    btn.backgroundColor=[UIColor redColor];
    [btn setTitle:@"暂停" forState:(UIControlStateNormal)];
    [btn addTarget:self action:@selector(labelizeSwitched) forControlEvents:(UIControlEventTouchUpInside)];
    
    
    
    UIButton *btn2=[UIButton buttonWithType:(UIButtonTypeCustom)];
    btn2.frame=CGRectMake(50, 250, 100, 30);
    btn2.backgroundColor=[UIColor redColor];
    [btn2 setTitle:@"开始" forState:(UIControlStateNormal)];
    [btn2 addTarget:self action:@selector(kaishi) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:btn2];
    
    [self.view addSubview:btn];

    
    [self.view addSubview:_lab];
    

    
}
//暂停(文字重置)
- (void)labelizeSwitched
{
    //暂停(重置文字)
    [_lab setLabelize:YES];

    //这种类型暂停 文字重置
//    [_lab resetLabel];
    //这种类型暂停 文字不重置
//    [_lab pauseLabel];
    
}
//开始
- (void)kaishi
{
    //对应 文字不重置暂停的开始
//    [_lab unpauseLabel];
    //对应 文字重置暂停的开始
//    [_lab restartLabel];
    // 文字重置对应的(开始)
    [_lab setLabelize:NO];

}
@end
//附图片

 

技术分享

技术分享

技术分享

//这是LabelTest.h 文件

 

#import <UIKit/UIKit.h>
#import "MarqueeLabel.h"

@interface LabelTest : UIViewController
@property (weak, nonatomic) IBOutlet MarqueeLabel *Label1;

@end

//附图片
技术分享

//这种方法需要在工程中导入 MarqueeLabel.h MarqueeLabel.m 文件 .在需要的地方导入头文件即可 然后把UILabel* Label; 写成这种形式的  MarqueeLabel *Label1;

 

ps:如有问题请加QQ850056672

 
 

实现Label中文字的滚动(跑马灯形式)

原文:http://www.cnblogs.com/ZhangPeng1127/p/4976830.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!