码迷,mamicode.com
首页 > 其他好文 > 详细

UIImage分类,设置边框

时间:2016-11-21 16:39:34      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:nim   height   裁剪   border   ini   name   new   分类   oval   

#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;
   
}

UIImage分类,设置边框

标签:nim   height   裁剪   border   ini   name   new   分类   oval   

原文地址:http://www.cnblogs.com/xsyl/p/6085878.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!