您的位置:首页 > 产品设计 > UI/UE

利用NStimer制作UILabel跑马灯效果

2015-08-19 00:00 519 查看
#import "ViewController.h"

@interface ViewController ()

@end

UILabel *mylabel;

@implementation ViewController

static int num=0;
-(void)timerAction:(NSTimer *)time{
num ++;
NSLog(@"Hi");
[mylabel removeFromSuperview];
CGRect workingFrame;
workingFrame.size.height=20;
workingFrame.size.width=600;
workingFrame.origin.x=430-num;
workingFrame.origin.y=400;

mylabel=[[UILabel alloc]initWithFrame:workingFrame];
mylabel.text=@"Hello world 01,Hello world 02,Hello world 03,Hello world 04";

mylabel.font=[UIFont systemFontOfSize:17];
[mylabel setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:mylabel] ;

if (num==1100) {
{
num=0;
}
}

}

- (void)viewDidLoad {
[super viewDidLoad];

[NSTimer scheduledTimerWithTimeInterval:0.025 target:self selector:@selector(timerAction:) userInfo:nil repeats:YES];

}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS 跑马灯