根据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.width, imageSize.height));

UIImage *pressedColorImg = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

时间: 2024-11-06 13:39:50

根据UIColor 创建UIImage的相关文章

五种创建UIImage的类方法

五种创建UIImage的类方法 UIImage有五个类方法,用来创建UIImage的.下面介绍一下每个类方法的作用和创建实例. 1.使用类方法imageNamed:创建 + (UIImage *)imageNamed:(NSString *)name; // load from main bundle name是照片名称.创建UIImage对象,代码如下: UIImage *image = [UIImage imageNamed:@"ganggang"]; 使用imageNamed:初

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 *)imageWithColor:(UIColor *)color { CGRect rect = CGRectMake(0, 0, 1, 1); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFill

通过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

创建UIImage的两种方法

1. UIImage *img = [UIImage imageNamed:@"imageName"]; 2. NSString *imageFilePath = [[NSBundle mainBundle] pathForResource:@"100" ofType:@"jpg"]; NSData *imageData = [NSData dataWithContentsOfFile:imageFilePath]; UIImage *image

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,