当前位置: 首页 > 工具软件 > UIImage-PDF > 使用案例 >

UIColor和UIImage转换

佴阳辉
2023-12-01

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"]]

 类似资料: