iOS笔记之UIImage与UIColor之间的转换

//UIColor 转UIImage(UIImage+YYAdd.m也是这种实现)
- (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:@"image.png"]];

你可能感兴趣的:(iOS笔记之UIImage与UIColor之间的转换)