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(context, [color CGColor]);

CGContextFillRect(context, rect);

UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return theImage;

}

UIImage转UIColor

[UIColor colorWithPatternImage:[UIImageimageNamed:@"EmailBackground.png"]]

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-28 04:59:37

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

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,

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

根据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

UIColor各种颜色转换

1.Hex值颜色转换 #import <UIKit/UIKit.h> @interface UIColor (Extension) // 根据无符号的32位整数转换为对应的RGB颜色 + (instancetype)sy_colorWithHex:(u_int32_t)hex; @end #import "UIColor+Extension.h" @implementation UIColor (Extension) + (instancetype)sy_colorWith

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