zoukankan      html  css  js  c++  java
  • UIImage分类,设置边框

    #import "UIImage+image.h"

    @implementation UIImage (image)

    + (UIImage *)imageWithBorder:(CGFloat)borderW color:(UIColor *)color image:(NSString *)imageName {
       
        // 增加边框 生成边框的宽度 w = image.width + 2*borderW 高度同理
        UIImage *image = [UIImage imageNamed:imageName];
       
        // 开启上下文
        CGSize size = CGSizeMake(image.size.width + 2 * borderW, image.size.height + 2 * borderW);
        UIGraphicsBeginImageContextWithOptions(size, NO, 0);
       
        // 绘制大圆,显示出来
        UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, size.width, size.height)];
        [[UIColor redColor] set];
        [path fill];
       
        // 绘小圆
        UIBezierPath *clipPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(borderW, borderW, image.size.width, image.size.height)];
        // 设置为裁剪路径
        [clipPath addClip];
       
        // 画图
        [image drawAtPoint:CGPointMake(borderW, borderW)];
        UIImage *newImage =  UIGraphicsGetImageFromCurrentImageContext();
       
        UIGraphicsEndImageContext();
       
        return newImage;
       
    }
  • 相关阅读:
    Geoserver通过ajax跨域访问服务数据的方法(含用户名密码认证的配置方式)
    123
    递归____蛮好的例子 蓝桥
    博弈_____威佐夫博奕
    123123
    sort
    int ,long , long long类型的范围
    数学推导_循环小数转分数
    下一步:结构体 背包 库函数
    回溯____蓝桥 棋盘
  • 原文地址:https://www.cnblogs.com/xsyl/p/6085878.html
Copyright © 2011-2022 走看看