您的位置:首页 > 移动开发 > IOS开发

IOS跑马灯效果

2016-02-17 11:54 190 查看
跑马灯效果

1、先声明一个全局的UILabel

UILabel *AD;

2、创建循环广告条-跑马灯

#pragma mark 创建循环广告条-跑马灯

-(void)creatADBar{

UIView *maskView = [[UIView alloc] initWithFrame:CGRectMake(50, 100, 100, 35)];

[self.view addSubview:maskView];

maskView.backgroundColor=[UIColor lightGrayColor];

maskView.clipsToBounds = YES;

AD = [[UILabel alloc]initWithFrame:CGRectMake(100, 0, 100, 35)];

[maskView addSubview:AD];

AD.text =@"循环广告播放。。。";

AD.textColor = [UIColor whiteColor];

AD.font = [UIFont systemFontOfSize:NormalFont];

}

3、设置跑马灯动画

#pragma mark 跑马灯动画

- (void)turnOverADBar{

CGFloat W = CGRectGetWidth(AD.bounds);

CGFloat H = CGRectGetHeight(AD.bounds);

[UIView animateWithDuration:5 animations:^{

AD.frame = CGRectMake(-W, 0, W, H);

} completion:^(BOOL finished) {

AD.frame = CGRectMake( W, 0, W, H);

[self turnOverADBar];

}];

}

4、viewDidLoad中调用,运行即可

- (void)viewDidLoad {

[super viewDidLoad];

[self creatADBar];

[self turnOverADBar];

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