ios Label TextFile 文本来回滚动 包括好用的三方
2017-07-05 16:41
323 查看
通常显示不够了,比如八个字。只能显示6个字。产品要求来回滚动
下面有两种方法:一种UIScrollView一种View动画如果不能满足你请点击这个https://github.com/cbpowell/MarqueeLabel好用的第三方
下面有两种方法:一种UIScrollView一种View动画如果不能满足你请点击这个
-(void)viewDidLoad { [superviewDidLoad]; self.view.backgroundColor=[UIColorblackColor]; //注册字体 REGISTER_FONT(bundleFont(@"新蒂小丸子体.ttf"),@"新蒂小丸子体"); //获取文本 NSString*string=@"喜欢这首情思幽幽的曲子,仿佛多么遥远,在感叹着前世的情缘,又是那么柔软,在祈愿着来世的缠绵。《莲的心事》,你似琉璃一样的晶莹,柔柔地拨动我多情的心弦。我,莲的心事,有谁知?我,莲的矜持,又有谁懂?"; //初始化label UILabel*label =[UILabelnew]; label.text =string; label.numberOfLines=0; label.textColor =[UIColorcyanColor]; label.font =[UIFontfontWithName:CUSTOM_FONT(@"新蒂小丸子体",0) size:20.f]; //计算尺寸 CGSizesize =[labelboundingRectWithSize:CGSizeMake(0,0)]; label.frame =(CGRect){CGPointZero,size}; //初始化ScrollView UIScrollView*showView=\ [[UIScrollViewalloc]initWithFrame:CGRectMake(0,90,320,size.height)]; showView.contentSize=size; showView.showsHorizontalScrollIndicator=NO; [showViewaddSubview:label]; [self.viewaddSubview:showView]; //形成边缘的遮罩 UIImageView*imageView=\ [[UIImageViewalloc]initWithFrame:CGRectMake(0,90,320,size.height)]; imageView.image=[UIImageimageNamed:@"bg"]; [self.viewaddSubview:imageView]; //动画 [UIViewanimateKeyframesWithDuration:10 delay:7 options:UIViewKeyframeAnimationOptionAllowUserInteraction animations:^{ //计算移动的距离 CGPointpoint=showView.contentOffset; point.x=size.width-320.f; showView.contentOffset=point; } completion:^(BOOLfinished){ }]; } 第二种简洁版
#import"Ridehorselight.h" @interfaceRidehorselight() @property(nonatomic,strong)NSTimer*timer;//定时器 @property(nonatomic,weak)UIView*viewAnima;//Label的背景 @property(nonatomic,weak)UILabel*customLabel;//Label @end @implementationRidehorselight -(void)viewDidLoad{ [superviewDidLoad]; //Doanyadditionalsetupafterloadingtheview. [selfaddClildView]; [selfsetTimer]; } -(void)addClildView{ self.view.backgroundColor=[UIColorwhiteColor]; CGFloatviewX=(self.view.frame.size.width-200)/2; UIView*viewAnima=[[UIViewalloc]initWithFrame:CGRectMake(viewX,100,200,40)]; viewAnima.backgroundColor=[UIColoryellowColor]; self.viewAnima=viewAnima; self.viewAnima.clipsToBounds=YES;//剪掉超出view范围部分 CGFloatcustomLabelY=(self.viewAnima.frame.size.height-30)/2; UILabel*customLabel=[[UILabelalloc]initWithFrame:CGRectMake(self.viewAnima.frame.size.width,customLabelY,200,30)]; customLabel.text=@"跑马灯效果,滚动文本!"; customLabel.textColor=[UIColorredColor]; self.customLabel=customLabel; [self.viewaddSubview:viewAnima]; [viewAnimaaddSubview:customLabel]; } -(void)setTimer{ self.timer=[NSTimerscheduledTimerWithTimeInterval:0.1target:selfselector:@selector(changePos)userInfo:nilrepeats:YES]; } -(void)changePos{ CGPointcenPos=self.customLabel.center; if(cenPos.x<-100){ CGFloatdistance=self.customLabel.frame.size.width/2; self.customLabel.center=CGPointMake(self.viewAnima.frame.size.width+distance,20); }else{ self.customLabel.center=CGPointMake(cenPos.x-5,20); } }
相关文章推荐
- iOS滚动Label滚动button--- VXXTextScrollView
- 走近Flex组件系列(五):数据组件(Dataehoose,DateFiled)与文本组件(Label,Text)
- 打开大文本文件工具(大于1G的文本文件)——Large Text File Viewer 5.2 - Features
- AndEngine绘制滚动文本TickerText
- IOS学习笔记(6)label textField textview
- ios开发 点击文本(TextField)输入的时候向上推以及输入之后恢复的动画
- 统计文本文件信息(Calculating Text File Statistics)
- ios中根据文本设置label高度
- coreText自定义富文本Label by Gphone
- (IOS系列)——TextFile属性设置
- TextView布局文件中实现文本过长时滚动显示效果
- Text_Label可以换行的文本下拉列表
- coreText自定义富文本Label
- iOS上的富文本控件-DTCoreTextView
- IOS学习笔记(6)label textField textview
- Flex中通过设置textAlign和labelStyleName样式设置FormItem容器中标签文本对齐方式的例子
- Android TextView多行文本滚动实现
- 动态创建Text或者Label并且控制文本颜色以及透明度
- 设置代码ios中根据文本设置label高度设置代码
- TextView 中长文本滚动显示(跑马灯效果)