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];
}
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];
}
相关文章推荐
- 培训机构出来的iOS学员怎么了?
- tabbar ios
- iOS关于启动页自定义特殊处理
- iOS开发——keychain的使用
- iOS上获取大文件md5的方法
- ios全部证书失效
- GitHub上值得关注的iOS开源项目
- iOS推送小结(证书的生成、客户端的开发、服务端的开发)
- iOS 设计模式之策略模式( Strategy)
- iOS 单选按钮
- 自身 iOS 技术水平的不足之处
- iOS之旅--轮播图封装使用教程
- 创建IOS项目的配置
- iOS 设计模式之简单工厂方法模式(SimpleFactoryMethod)
- IOS本地地图使用
- 此证书的签发者无效Missing iOS Distribution signing identity问题解决
- iOS-NSMutableAttributedString富文本的实现
- iosanimationWithKeyPath
- IOS storyboard解决TableViewCell底线无法到头问题
- iOS实现图片保存与搜索功能