在做歌词的时候,有时候歌词颜色会发生变化 ,一般会用UIImage做剪裁,慢慢出现不同的颜色,用UIlable专为UIImage,图片进行绘图操作就可以达到想要的效果了
label转化成image:
- (UIImage*) imageWithUIView:(UIView*) view
{
UIGraphicsBeginImageContext(view.bounds.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[view.layer renderInContext:ctx];
UIImage* tImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return tImage;
}
然后进行绘图剪裁
- (UIImage *)croppedImage:(UIImage *)image cutRect:(NSInteger)width
{
if (image)
{
float min = MIN(image.size.width,image.size.height);
CGRect rectMAX = CGRectMake(0, 0, width, min);
CGImageRef subImageRef = CGImageCreateWithImageInRect(image.CGImage, rectMAX);
UIGraphicsBeginImageContext(rectMAX.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, CGRectMake(0, 0, width, min), subImageRef);
UIImage *viewImage = [UIImage imageWithCGImage:subImageRef];
UIGraphicsEndImageContext();
CGImageRelease(subImageRef);
return viewImage;
}
return nil;
}
这样就可以根据时间出现缓慢的出现歌词了。。。。。。