UIcolor转UIImage

+ (UIImage *)imageWithColor:(UIColor *)color {

CGRect rect = CGRectMake(0, 0, 1, 1);

UIGraphicsBeginImageContext(rect.size);

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [color CGColor]);

CGContextFillRect(context, rect);

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return image;

}

时间: 2024-11-07 22:44:03

UIcolor转UIImage的相关文章

iOS开发-UIColor和UIImage之间的转换

UIColor 转UIImage(可将该方法作为一个UIImage的分类) - (UIImage *)imageWithColor:(UIColor *)color { //描述一个矩形 CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); //开启图形上下文 UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0); //获得图形上下文 CGContextRef ctx = UIGraphic

UIColor和UIImage转换

UIColor 转UIImage - (UIImage*) createImageWithColor: (UIColor*) color { CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(contex

通过UIColor转换为UIImage

+ (UIImage *)createImageWithColor:(UIColor *)color { CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]

iOS 将UIColor转换为UIImage

/** * 将UIColor变换为UIImage * **/+ (UIImage *)createImageWithColor:(UIColor *)color{ CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWit

根据UIColor 创建UIImage

CGSize imageSize = CGSizeMake(self.doneButton.frame.size.width, self.doneButton.frame.size.height); UIGraphicsBeginImageContextWithOptions(imageSize, 0, [UIScreen mainScreen].scale); [[UIColor whiteColor] set]; UIRectFill(CGRectMake(0, 0, imageSize.w

UIImage与UIColor互转

Objective-C UIColor -> UIImage ? 1 2 3 4 5 6 7 8 9 10 11 - (UIImage*) createImageWithColor: (UIColor*) color {     CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);     UIGraphicsBeginImageContext(rect.size);     CGContextRef context = UIGraphicsGetCur

iOS中UIImage和UIColor之间的转换

//UIColor 转UIImage - (UIImage*)imageWithColor: (UIColor*)color { CGRect rect=CGRectMake(0.0f, 0.0f, 100.0f, 50.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context,

IOS中UIImage和UIColor相互转化

//UIColor 转UIImage - (UIImage*) createImageWithColor: (UIColor*) color { CGRect rect=CGRectMake(0, 0, 1, 1); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color 

UIImage,UIImageView的使用

1.UIImage 创建UIImage的两种方法 UIImage *image = [UIImage imageNamed:imageNmae]; UIImage *image = [UIImage imageWithContentsOfFile:imageNmae]; - imageNamed这个方法会自动缓存创建的图片 - 如果图片不是经常使用(比如汤姆猫), 并且图片非常占用资源, 那么不建议使用imageNamed方法加载图片 2.UIImageView - 如果是通过[[UIImage