//通过颜色制作图片
- (UIImage *)imageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
本文提供了一个Swift代码示例,演示如何通过指定的颜色创建一张纯色图片。通过使用Core Graphics API,可以轻松地创建不同颜色的图片,为iOS应用开发者提供便利。
2521

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



