zoukankan      html  css  js  c++  java
  • ios --图片文字组合头像那点事

    /**
     图片文字组合头像那点事
    
     @param string 昵称
     @param imageSize 图片尺寸
     @param imageColor 图片颜色
     @return 返回的 图片
     */
    + (UIImage *)gl_creatImageWithString:(NSAttributedString *)string
                               imageSize:(CGSize)imageSize
                              imageColor:(UIColor *)imageColor
    {
        //通过自己创建一个context来绘制,通常用于对图片的处理
        UIGraphicsBeginImageContextWithOptions(imageSize, NO, [UIScreen mainScreen].scale);
        //获取上下文
        CGContextRef context = UIGraphicsGetCurrentContext();
        //设置填充颜色
        CGContextSetFillColorWithColor(context, imageColor.CGColor);
        //直接按rect的范围覆盖
        CGContextAddEllipseInRect(context, CGRectMake(0, 0, imageSize.width, imageSize.height));
        CGContextFillPath(context);
        
        CGSize stringSize = [string size];
        CGFloat x = (imageSize.width - stringSize.width)/2.0;
        CGFloat y = (imageSize.height - stringSize.height)/2.0;
        
        [string drawInRect:CGRectMake(x, y, stringSize.width, stringSize.height)];
        
        UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return newimg;
    }
  • 相关阅读:
    借鉴文章记录
    三方框架
    常用第三方库记录
    ios block 类型
    ios runtime部分事例方法说明
    ios url网址相关问题解说
    mysql迁移数据库函数中的坑
    mysql的事务隔离级别
    MySQL数据库的默认隔离级别为什么是可重复读
    实时查看mysql连接数
  • 原文地址:https://www.cnblogs.com/shenlaiyaoshi/p/9565364.html
Copyright © 2011-2022 走看看