在做歌词的时候,有时候歌词颜色会发生变化 ,一般会用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;
}这样就可以根据时间出现缓慢的出现歌词了。。。。。。
本文介绍了一种通过将UILabel转化为UIImage,并对其进行绘图剪裁来实现歌词颜色随时间逐渐变化的方法。利用UIKit框架中的基本图形处理功能,可以制作出歌词颜色平滑过渡的效果。
405

被折叠的 条评论
为什么被折叠?



