一段关于文字音乐高光效果的设置代码摘录.
来源:互联网 发布:叶根友特楷简体 mac版 编辑:程序博客网 时间:2024/06/05 07:08
本段代码转自一个示例代码.
播放器文字高光效果:
-(void)settext:(NSString *)te
{
if (text!=nil)
{
[text release];
text = nil;
}
text = [te retain];
CGSize size1 = [text sizeWithFont:FONT];
NSLog(@"%f %f",size1.width,size1.height);
CGSize size = [text sizeWithFont:FONT constrainedToSize:self.frame.size
lineBreakMode:UILineBreakModeWordWrap];
NSLog(@"%f %f",size.width,size.height);
linenum = size.height/size1.height;
hight = size.height;
len = 0;
if ([t isValid])
{
[t invalidate];
[t release];
}
t = [[NSTimer alloc] initWithFireDate:[NSDate date] interval:0.01 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:t forMode:NSDefaultRunLoopMode];
[self setNeedsDisplay];
}
-(void)timerFired:(NSTimer*)timer
{
NSLog(@"timer运行");
//[t invalidate];
//[t release];
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect
{
int linew = rect.size.width;
int linehighe = hight/linenum;
int line = len/linew;
int linex = len%linew;
NSLog(@"行数:%d 烈数:%d",line,linex);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0, rect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
if (line>0)
{
CGContextSetRGBFillColor(context, 1, 1, 1, 1);
CGContextFillRect(context, CGRectMake(0.0,0.0,linew,line*linehighe));
}
if (linex>0)
{
CGContextSetRGBFillColor(context, 1, 1, 1, 1);
CGContextFillRect(context, CGRectMake(0.0,line*linehighe,linex,linehighe));
}
CGContextSetRGBFillColor(context, 0.5, 0.1, 0.8, 1);
CGContextFillRect(context, CGRectMake(linex,line*linehighe,linew - linex,linehighe));
CGContextFillRect(context, CGRectMake(0.0,(line+1)*linehighe,linew,(linenum-1-line)*linehighe));
CGImageRef alphaMask = CGBitmapContextCreateImage(context);
CGContextRestoreGState(context);
/*
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextSetRGBFillColor(context, 0.5, 0.1, 0.8, 1);
CGContextFillRect(context, CGRectMake(0.0, 0.0, rect.size.width/2,rect.size.height));
CGContextSetRGBFillColor(context, 1, 1, 1, 1);
CGContextFillRect(context, CGRectMake(rect.size.width/2, 0, rect.size.width/2,rect.size.height));
CGImageRef alphaMask = CGBitmapContextCreateImage(context);
CGContextRestoreGState(context);
*/
CGContextSetRGBFillColor(context, 0.5, 0.5, 0.5, 1);
CGContextFillRect(context, rect);
CGContextClipToMask(context, rect, alphaMask);
[[UIColor greenColor] setFill];
[text drawInRect:rect withFont:FONT];
CGImageRelease(alphaMask);
CGContextRestoreGState(context);
len++;
}
- 一段关于文字音乐高光效果的设置代码摘录.
- Xcode5 去掉Icon高光效果 设置
- 一段设置和取消windows静音效果的Delphi代码
- 使用shaderMaterial实现平行光下的高光效果
- 高光效果
- 一段关于继承和类的文字
- 关于回文的一段代码
- 关于Const的一段代码
- 一段关于webGL的代码
- 关于kdtree的一段代码
- 一段关于linq的代码
- 一段关于tableViewController的代码
- 关于数组的一段代码
- 关于string的一段代码
- 一段关于静态的代码
- 如何使用Vegas制作文字的扫光效果?
- 测试 加入一段代码的效果
- 一段不错的代码,动态效果
- 6.087 Practical Programming in C, lec4:More control flow. Input and output.
- linux设备驱动程序(第三版)读书笔记2
- 正确的加载DLL
- document.location.reload和document.location.href的比较
- do...while(0)的妙用
- 一段关于文字音乐高光效果的设置代码摘录.
- 常用命令行
- 每天进步一点点
- C中的可变参数
- 详解Java解析XML的四种方法
- MultiByteToWideChar
- Oracle SQL 内置函数大全
- 自己的内核制作过程
- collectd调研