美文网首页开发锦集
颜色转图片、View转图片

颜色转图片、View转图片

作者: YvanLiu | 来源:发表于2017-03-27 19:00 被阅读22次
1、颜色转图片
+ (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*image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
2、View转图片(截屏)
+ (UIImage *)createImageWihtView:(UIView *)view {
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, view.layer.contentsScale);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

相关文章

网友评论

    本文标题:颜色转图片、View转图片

    本文链接:https://www.haomeiwen.com/subject/zrorottx.html