label中的文字类似跑马灯的效果
来源:互联网 发布:python statement 编辑:程序博客网 时间:2024/05/10 15:09
label中的文字类似跑马灯的效果
#import <UIKit/UIKit.h>
@interface MyLabel : UIViewController {
UILabel *label;
UILabel *big;
}
@property (nonatomic, retain) UILabel *label;
@property (nonatomic, retain) UILabel *big;
-(id)initWithMyFrame:(CGRect)frame;
-(void)startAnimation:(NSString *)string;
@end
m文件:
#import "MyLabel.h"
@implementation MyLabel
@synthesize label,big;
-(id)initWithMyFrame:(CGRect)frame
{
self = [super init];
if(self)
{
self.view = [[UIView alloc] initWithFrame:frame];
}
label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
big = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
[self.view insertSubview:big atIndex:0];
[big setBackgroundColor:[UIColor clearColor]];
[big setTextColor:[UIColor whiteColor]];
[self.view setBackgroundColor:[UIColor clearColor]];
[self.view setClipsToBounds:YES];//移动到view外面的不显示
return self;
}
-(void)startAnimation:(NSString *)string
{
int length = [string length];
CGRect labFrame = self.label.frame;
CGSize labSize = labFrame.size;
UIFont *font = [UIFont fontWithName:@"Georgia-Bold" size:17];
[big setFont:font];
if(length * 17 < labSize.width)
{
[big.layer removeAnimationForKey:@"animateLayer"];
big.frame = CGRectMake(0, 0, length*17, self.label.frame.size.height);
big.text = string;
//[CATransaction commit];//如果这里再次提交,就把anmiation给取消掉了,因为frame重设,removeanimation了。
}
else
{
big.text = string;
big.frame = CGRectMake(self.label.frame.size.width, 0, length*17, self.label.frame.size.height);
//[CATransaction commit];//如果在这里提交会覆盖上一个animation的效果
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation.duration=3;
theAnimation.repeatCount=999999;
theAnimation.autoreverses=NO;
theAnimation.toValue=[NSNumber numberWithFloat:-length*17-self.label.frame.size.width];
[big.layer addAnimation:theAnimation forKey:@"animateLayer"];
}
}
- (void)dealloc {
[big release];
[label release];
}
@end
- label中的文字类似跑马灯的效果
- 文字的跑马灯效果
- 文字跑马灯效果
- 文字 跑马灯 效果
- 文字跑马灯效果
- 文字跑马灯效果
- 文字跑马灯效果
- 文字跑马灯效果
- android 文字的跑马灯效果
- android 文字的跑马灯效果
- 实现文字的跑马灯效果,Textview
- Android 文字跑马灯效果
- Android 文字跑马灯效果
- android 文字跑马灯效果
- 文字跑马灯效果代码
- TextView文字跑马灯效果
- TextView跑马灯效果,也就是,自动滚动文字的效果。
- Label 控件实现跑马灯效果
- ZOJ-3931-Exact Compression【dp】【bitset】【好题】
- Android WebView缓存机制详解
- J2EE中使用jstl报http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar错
- SlideMenuDemo
- 为什么要加上拉电阻和下拉电阻
- label中的文字类似跑马灯的效果
- 基于状态机的调度机制需要包含的四个要素
- Redis 字符串处理命令
- Skyline创建三维管线两种方式(C#)
- boost::scoped_ptr用法
- android 5.0预制APK
- 为什么要有层次结构?
- 组队列,下载图片,完成后拼接图片
- Web应用——驾培管理系统之系统—权限分配