drawRect简单封装

#define kBlackColor [UIColor blackColor]

//.h

//划线

+ (void)drawLineMoveToPoint:(CGPoint)point addLineToPoint:(CGPoint)linePoint;

+ (void)drawLineMoveToPoint:(CGPoint)point addLineToPoint:(CGPoint)linePoint lineWidth:(CGFloat)width;

+ (void)drawLineMoveToPoint:(CGPoint)point addLineToPoint:(CGPoint)linePoint lineWidth:(CGFloat)width lineColor:(UIColor *)lineColor;

+ (void)drawLinePointArray:(NSArray*)pointArray lineWidth:(CGFloat)width strokeColor:(UIColor *)strokeColor;

+ (void)drawLinePointArray:(NSArray*)pointArray lineWidth:(CGFloat)width fillColor:(UIColor *)fillColor;

+ (void)drawLinePointArray:(NSArray*)pointArray lineWidth:(CGFloat)width strokeColor:(UIColor *)strokeColor fillColor:(UIColor *)fillColor;

//画矩形

+ (void)drawRect:(CGRect)rect;

+ (void)drawRect:(CGRect)rect lineWidth:(CGFloat)width;

+ (void)drawRect:(CGRect)rect lineWidth:(CGFloat)width strokeColor:(UIColor *)strokeColor;

+ (void)drawRect:(CGRect)rect lineWidth:(CGFloat)width fillColor:(UIColor *)fillColor;

+ (void)drawRect:(CGRect)rect lineWidth:(CGFloat)width strokeColor:(UIColor *)strokeColor fillColor:(UIColor *)fillColor;

//画曲线

//int clockwise  0顺时针  1逆时针,默认是0

//Angle

+ (void)drawCurveCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle;

+ (void)drawCurveCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle lineWidth:(CGFloat)width;

+ (void)drawCurveCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle lineWidth:(CGFloat)width lineColor:(UIColor *)lineColor;

+ (void)drawCurveCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(int)clockwise;

+ (void)drawCurveCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(int)clockwise lineWidth:(CGFloat)width;

+ (void)drawCurveCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(int)clockwise lineWidth:(CGFloat)width lineColor:(UIColor *)lineColor;

//point + radius

+ (void)drawCurveWithStartPoint:(CGPoint)startPoint focusPoint:(CGPoint)focusPoint endPoint:(CGPoint)endPoint radius:(CGFloat)radius;

+ (void)drawCurveWithStartPoint:(CGPoint)startPoint focusPoint:(CGPoint)focusPoint endPoint:(CGPoint)endPoint radius:(CGFloat)radius lineWidth:(CGFloat)width;

+ (void)drawCurveWithStartPoint:(CGPoint)startPoint focusPoint:(CGPoint)focusPoint endPoint:(CGPoint)endPoint radius:(CGFloat)radius lineWidth:(CGFloat)width lineColor:(UIColor *)lineColor;

//画圆

//双填充

+ (void)drawCircleFrame:(CGRect)frame;

+ (void)drawCircleFrame:(CGRect)frame color:(UIColor *)color;

+ (void)drawCircleCenter:(CGPoint)center radius:(CGFloat)radius;

+ (void)drawCircleCenter:(CGPoint)center radius:(CGFloat)radius color:(UIColor *)color;

//外填充

//默认线宽为1

+ (void)drawCircleFrame:(CGRect)frame trokeColor:(UIColor *)trokeColor;

+ (void)drawCircleFrame:(CGRect)frame lineWidth:(CGFloat)lineWidth trokeColor:(UIColor *)trokeColor;

+ (void)drawCircleCenter:(CGPoint)center radius:(CGFloat)radius strokeColor:(UIColor *)strokeColor;

+ (void)drawCircleCenter:(CGPoint)center radius:(CGFloat)radius lineWidth:(CGFloat)width strokeColor:(UIColor *)strokeColor;

//内填充

+ (void)drawCircleFrame:(CGRect)frame fillColor:(UIColor *)fillColor;

+ (void)drawCircleCenter:(CGPoint)center radius:(CGFloat)radius fillColor:(UIColor *)fillColor;

//画饼

+ (void)drawCakeCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle;

+ (void)drawCakeCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle color:(UIColor *)color;

+ (void)drawCakeCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle  clockwise:(int)clockwise color:(UIColor *)color;

//字符串

//默认字体:40 颜色:黑色 位置:屏幕中心

+ (void)drawString:(NSString *)str;

//location

+ (void)drawString:(NSString *)str center:(CGPoint)center;

+ (void)drawString:(NSString *)str rect:(CGRect)rect;

//font

+ (void)drawString:(NSString *)str font:(UIFont *)font;

+ (void)drawString:(NSString *)str center:(CGPoint)center font:(UIFont *)font;

+ (void)drawString:(NSString *)str rect:(CGRect)rect font:(UIFont *)font;

//color

+ (void)drawString:(NSString *)str color:(UIColor *)color;

+ (void)drawString:(NSString *)str center:(CGPoint)center color:(UIColor *)color;

+ (void)drawString:(NSString *)str rect:(CGRect)rect color:(UIColor *)color;

+ (void)drawString:(NSString *)str center:(CGPoint)center font:(UIFont *)font color:(UIColor *)color;

+ (void)drawString:(NSString *)str rect:(CGRect)rect font:(UIFont *)font color:(UIColor *)color;

//图片

//默认位置:屏幕中心

+ (void)drawImage:(UIImage *)image;

+ (void)drawImage:(UIImage *)image center:(CGPoint)center;

+ (void)drawImage:(UIImage *)image point:(CGPoint)point;

+ (void)drawImage:(UIImage *)image rect:(CGRect)rect;

//旋转角度

//默认中心旋转

+ (void)drawImage:(UIImage *)image center:(CGPoint)center angle:(CGFloat)angle;

+ (void)drawImage:(UIImage *)image point:(CGPoint)point angle:(CGFloat)angle;

+ (void)drawImage:(UIImage *)image rect:(CGRect)rect angle:(CGFloat)angle;

//设置旋转点

+ (void)drawImage:(UIImage *)image center:(CGPoint)center translate:(CGPoint)translate angle:(CGFloat)angle;

+ (void)drawImage:(UIImage *)image point:(CGPoint)point translate:(CGPoint)translate angle:(CGFloat)angle;

+ (void)drawImage:(UIImage *)image rect:(CGRect)rect translate:(CGPoint)translate angle:(CGFloat)angle;

//.m

//划线

+ (void)drawLineMoveToPoint:(CGPoint)point addLineToPoint:(CGPoint)linePoint; {

[self drawLineMoveToPoint:point addLineToPoint:linePoint lineWidth:1 lineColor:kBlackColor];

}

+ (void)drawLineMoveToPoint:(CGPoint)point addLineToPoint:(CGPoint)linePoint lineWidth:(CGFloat)width {

[self drawLineMoveToPoint:point addLineToPoint:linePoint lineWidth:width lineColor:kBlackColor];

}

+ (void)drawLineMoveToPoint:(CGPoint)point addLineToPoint:(CGPoint)linePoint lineWidth:(CGFloat)width lineColor:(UIColor *)lineColor {

[self drawLinePointArray:@[kValueFromPoint(point.x, point.y),kValueFromPoint(linePoint.x, linePoint.y)] lineWidth:width strokeColor:lineColor];

}

+ (void)drawLinePointArray:(NSArray*)pointArray lineWidth:(CGFloat)width strokeColor:(UIColor *)strokeColor {

//获取上下文

CGContextRef    ref = UIGraphicsGetCurrentContext();

//配置

//设置直线的起点

NSValue  *firstValue = [pointArray firstObject];

CGPoint  firstPoint = kPointFromValue(firstValue);

CGContextMoveToPoint(ref, firstPoint.x,firstPoint.y);

//设置直线的下一个点

for (int i = 1; i < pointArray.count; i ++) {

NSValue  *value = pointArray[i];

CGPoint  point = kPointFromValue(value);

CGContextAddLineToPoint(ref, point.x, point.y);

}

[strokeColor setStroke];

//设置直线的线宽

CGContextSetLineWidth(ref, width);

//设置直线起点的样式

CGContextSetLineCap(ref, kCGLineCapRound);

//连接

CGContextSetLineJoin(ref, kCGLineJoinRound);

CGContextStrokePath(ref);

}

+ (void)drawLinePointArray:(NSArray*)pointArray lineWidth:(CGFloat)width fillColor:(UIColor *)fillColor {

//获取上下文

CGContextRef    ref = UIGraphicsGetCurrentContext();

//配置

//设置直线的起点

NSValue  *firstValue = [pointArray firstObject];

CGPoint  firstPoint = kPointFromValue(firstValue);

CGContextMoveToPoint(ref, firstPoint.x,firstPoint.y);

//设置直线的下一个点

for (int i = 1; i < pointArray.count; i ++) {

NSValue  *value = pointArray[i];

CGPoint  point = kPointFromValue(value);

CGContextAddLineToPoint(ref, point.x, point.y);

}

CGContextClosePath(ref);

[fillColor setFill];

//设置直线的线宽

CGContextSetLineWidth(ref, width);

//设置直线起点的样式

CGContextSetLineCap(ref, kCGLineCapRound);

//连接

CGContextSetLineJoin(ref, kCGLineJoinRound);

CGContextFillPath(ref);

}

+ (void)drawLinePointArray:(NSArray*)pointArray lineWidth:(CGFloat)width strokeColor:(UIColor *)strokeColor fillColor:(UIColor *)fillColor {

if (pointArray.count < 2) {

return;

}

if (strokeColor) {

[self drawLinePointArray:pointArray lineWidth:width strokeColor:strokeColor];

}

if (fillColor) {

[self drawLinePointArray:pointArray lineWidth:width fillColor:fillColor];

}

}

//画矩形

+ (void)drawRect:(CGRect)rect {

[self drawRect:rect lineWidth:1];

}

+ (void)drawRect:(CGRect)rect lineWidth:(CGFloat)width {

[self drawRect:rect lineWidth:width strokeColor:kBlackColor];

}

+ (void)drawRect:(CGRect)rect lineWidth:(CGFloat)width strokeColor:(UIColor *)strokeColor {

//获取上下文

CGContextRef    ref = UIGraphicsGetCurrentContext();

CGContextAddRect(ref, rect);

//设置直线的线宽

CGContextSetLineWidth(ref, width);

//设置直线起点的样式

CGContextSetLineCap(ref, kCGLineCapRound);

[strokeColor setStroke];

CGContextStrokePath(ref);

}

+ (void)drawRect:(CGRect)rect lineWidth:(CGFloat)width fillColor:(UIColor *)fillColor {

//获取上下文

CGContextRef    ref = UIGraphicsGetCurrentContext();

CGContextAddRect(ref, rect);

//设置直线的线宽

CGContextSetLineWidth(ref, width);

//设置直线起点的样式

CGContextSetLineCap(ref, kCGLineCapRound);

[fillColor setFill];

CGContextFillPath(ref);

}

+ (void)drawRect:(CGRect)rect lineWidth:(CGFloat)width strokeColor:(UIColor *)strokeColor fillColor:(UIColor *)fillColor {

if (fillColor) {

[self drawRect:rect lineWidth:width fillColor:fillColor];

}

if (strokeColor) {

[self drawRect:rect lineWidth:width strokeColor:strokeColor];

}

}

//画曲线

//int clockwise  0顺时针  1逆时针

//angle

+ (void)drawCurveCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle {

[self drawCurveCenter:circleCenter radius:radius startAngle:startAngle endAngle:endAngle clockwise:0 lineWidth:1 lineColor:kBlackColor];

}

+ (void)drawCurveCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle lineWidth:(CGFloat)width {

[self drawCurveCenter:circleCenter radius:radius startAngle:startAngle endAngle:endAngle clockwise:0 lineWidth:width lineColor:kBlackColor];

}

+ (void)drawCurveCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle lineWidth:(CGFloat)width lineColor:(UIColor *)lineColor {

[self drawCurveCenter:circleCenter radius:radius startAngle:startAngle endAngle:endAngle clockwise:0 lineWidth:width lineColor:lineColor];

}

+ (void)drawCurveCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(int)clockwise {

[self drawCurveCenter:circleCenter radius:radius startAngle:startAngle endAngle:endAngle clockwise:clockwise lineWidth:1 lineColor:kBlackColor];

}

+ (void)drawCurveCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(int)clockwise lineWidth:(CGFloat)width {

[self drawCurveCenter:circleCenter radius:radius startAngle:startAngle endAngle:endAngle clockwise:clockwise lineWidth:width lineColor:kBlackColor];

}

+ (void)drawCurveCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(int)clockwise lineWidth:(CGFloat)width lineColor:(UIColor *)lineColor {

CGContextRef  ref = UIGraphicsGetCurrentContext();

//int clockwise  0顺时针  1逆时针

CGContextAddArc(ref, circleCenter.x, circleCenter.y, radius, startAngle, endAngle, clockwise);

//    CGContextAddArc(<#CGContextRef  _Nullable c#>, <#CGFloat x#>, <#CGFloat y#>, <#CGFloat radius#>, CGFloat startAngle, CGFloat endAngle, int clockwise)

CGContextSetLineWidth(ref, width);

if (lineColor) {

[lineColor setStroke];

}

CGContextStrokePath(ref);

}

//point + radius

+ (void)drawCurveWithStartPoint:(CGPoint)startPoint focusPoint:(CGPoint)focusPoint endPoint:(CGPoint)endPoint radius:(CGFloat)radius {

[self drawCurveWithStartPoint:startPoint focusPoint:focusPoint endPoint:endPoint radius:radius lineWidth:1 lineColor:kBlackColor];

}

+ (void)drawCurveWithStartPoint:(CGPoint)startPoint focusPoint:(CGPoint)focusPoint endPoint:(CGPoint)endPoint radius:(CGFloat)radius lineWidth:(CGFloat)width {

[self drawCurveWithStartPoint:startPoint focusPoint:focusPoint endPoint:endPoint radius:radius lineWidth:width lineColor:kBlackColor];

}

+ (void)drawCurveWithStartPoint:(CGPoint)startPoint focusPoint:(CGPoint)focusPoint endPoint:(CGPoint)endPoint radius:(CGFloat)radius lineWidth:(CGFloat)width lineColor:(UIColor *)lineColor {

//    if (startPoint.x == endPoint.x && startPoint.y == endPoint.y) {

//        return;

//    }

//

//    CGFloat  f_x = fabs(endPoint.x - startPoint.x);

//    CGFloat  f_y = fabs(endPoint.y - startPoint.y);

//    CGFloat  s_d = sqrt(f_x * f_x + f_y * f_y);

//

//    CGFloat  f_x_h = f_x * 0.5;

//    CGFloat  f_y_h = f_y * 0.5;

//    CGFloat  s_d_h = s_d * 0.5;

//

//    CGFloat  D_X = f_x * sqrt(radius * radius - s_d_h * s_d_h) / s_d;

//

//    if (s_d_h > radius) {

//        return;

//    }

//

//

//    CGPoint  center = CGPointZero;

//

//    if (startPoint.x == endPoint.x) {

//

//        if (startPoint.y < endPoint.y) {

//

//            if (clockwise) {

//

//                center = CGPointMake(startPoint.x - sqrt(radius * radius - f_y_h * f_y_h) , f_y_h + startPoint.y);

//            }else {

//

//                center = CGPointMake(startPoint.x + sqrt(radius * radius - f_y_h * f_y_h) , f_y_h + startPoint.y);

//            }

//

//

//        }else {

//

//            if (clockwise) {

//

//                center = CGPointMake(startPoint.x + sqrt(radius * radius - f_y_h * f_y_h) , f_y_h + startPoint.y);

//            }else {

//

//                center = CGPointMake(startPoint.x - sqrt(radius * radius - f_y_h * f_y_h) , f_y_h + startPoint.y);

//            }

//

//

//        }

//    }else if (startPoint.y == endPoint.y) {

//

//        if (startPoint.x < endPoint.x) {

//

//            if (clockwise) {

//

//                center = CGPointMake(startPoint.x + f_x_h ,startPoint.y + sqrt(radius * radius - f_x_h * f_x_h));

//            }else {

//

//                center = CGPointMake(startPoint.x + f_x_h ,startPoint.y - sqrt(radius * radius - f_x_h * f_x_h));

//            }

//

//

//        }else {

//

//            if (clockwise) {

//

//                center = CGPointMake(startPoint.x + f_x_h ,startPoint.y - sqrt(radius * radius - f_x_h * f_x_h));

//            }else {

//

//                center = CGPointMake(startPoint.x + f_x_h ,startPoint.y + sqrt(radius * radius - f_x_h * f_x_h));

//            }

//        }

//    }else if (startPoint.x > endPoint.x && startPoint.y > endPoint.y) {

//

//        if (clockwise) {

//

//            center = CGPointMake(startPoint.x + sqrt(radius * radius - sqrt(D_X + f_y_h) * (sqrt(D_X + f_y_h))), startPoint.y - f_y_h - D_X);

//        }else {

//

//            center = CGPointMake(startPoint.x - sqrt(radius * radius - sqrt(f_y_h - D_X) * (sqrt(D_X + f_y_h))), startPoint.y - f_y_h + D_X);

//        }

//

//    }else if (startPoint.x > endPoint.x && startPoint.y < endPoint.y) {

//

//        if (clockwise) {

//

//            center = CGPointMake(endPoint.x - sqrt(radius * radius - sqrt(D_X + f_y_h) * (sqrt(D_X + f_y_h))), endPoint.y - f_y_h - D_X);

//        }else {

//

//            center = CGPointMake(startPoint.x + sqrt(radius * radius - sqrt(D_X + f_y_h) * (sqrt(D_X + f_y_h))), startPoint.y + f_y_h + D_X);

//        }

//

//    }else if (startPoint.x < endPoint.x && startPoint.y > endPoint.y) {

//

//        if (clockwise) {

//

//            center = CGPointMake(endPoint.x + sqrt(radius * radius - sqrt(D_X + f_y_h) * (sqrt(D_X + f_y_h))), endPoint.y + f_y_h + D_X);

//

//        }else {

//

//            center = CGPointMake(startPoint.x - sqrt(radius * radius - sqrt(D_X + f_y_h) * (sqrt(D_X + f_y_h))), startPoint.y - f_y_h - D_X);

//

//        }

//

//    }else if (startPoint.x < endPoint.x && startPoint.y < startPoint.y) {

//

//        if (clockwise) {

//

//            center = CGPointMake(endPoint.x + sqrt(radius * radius - sqrt(D_X + f_y_h) * (sqrt(D_X + f_y_h))), endPoint.y - f_y_h - D_X);

//        }else {

//

//            center = CGPointMake(endPoint.x - sqrt(radius * radius - sqrt(f_y_h - D_X) * (sqrt(D_X + f_y_h))), endPoint.y - f_y_h + D_X);

//        }

//

//    }

CGContextRef  ref = UIGraphicsGetCurrentContext();

CGContextMoveToPoint(ref, startPoint.x, startPoint.y);

CGContextAddArcToPoint(ref, focusPoint.x, focusPoint.y, endPoint.x, endPoint.y, radius);

CGContextSetLineWidth(ref, width);

if (lineColor) {

[lineColor setStroke];

}else {

[kBlackColor setStroke];

}

CGContextStrokePath(ref);

}

//画圆

//双填充

+ (void)drawCircleFrame:(CGRect)frame {

[self drawCircleFrame:frame color:kBlackColor];

}

+ (void)drawCircleFrame:(CGRect)frame color:(UIColor *)color {

CGContextRef  ref = UIGraphicsGetCurrentContext();

CGContextAddEllipseInRect(ref, frame);

if (color) {

[color set];

}

CGContextFillPath(ref);

}

+ (void)drawCircleCenter:(CGPoint)center radius:(CGFloat)radius {

[self drawCircleFrame:CGRectMake(center.x - radius, center.y - radius, radius * 2, radius * 2)];

}

+ (void)drawCircleCenter:(CGPoint)center radius:(CGFloat)radius color:(UIColor *)color {

[self drawCircleFrame:CGRectMake(center.x - radius, center.y - radius, radius * 2, radius * 2) color:color];

}

//外填充

//默认线宽为1

+ (void)drawCircleFrame:(CGRect)frame trokeColor:(UIColor *)trokeColor {

[self drawCircleFrame:frame lineWidth:1.0 trokeColor:trokeColor];

}

+ (void)drawCircleFrame:(CGRect)frame lineWidth:(CGFloat)lineWidth trokeColor:(UIColor *)trokeColor {

CGContextRef  ref = UIGraphicsGetCurrentContext();

CGContextAddEllipseInRect(ref, frame);

CGContextSetLineWidth(ref, lineWidth);//线的宽度

if (trokeColor) {

[trokeColor setStroke];

}

CGContextStrokePath(ref);

}

+ (void)drawCircleCenter:(CGPoint)center radius:(CGFloat)radius strokeColor:(UIColor *)strokeColor {

[self drawCircleFrame:CGRectMake(center.x - radius, center.y - radius, radius * 2, radius * 2) lineWidth:1 trokeColor:strokeColor];

}

+ (void)drawCircleCenter:(CGPoint)center radius:(CGFloat)radius lineWidth:(CGFloat)width strokeColor:(UIColor *)strokeColor {

[self drawCircleFrame:CGRectMake(center.x - radius, center.y - radius, radius * 2, radius * 2) lineWidth:width trokeColor:strokeColor];

}

//内填充

+ (void)drawCircleFrame:(CGRect)frame fillColor:(UIColor *)fillColor {

CGContextRef  ref = UIGraphicsGetCurrentContext();

CGContextAddEllipseInRect(ref, frame);

if (fillColor) {

[fillColor setFill];

}

CGContextFillPath(ref);

}

+ (void)drawCircleCenter:(CGPoint)center radius:(CGFloat)radius fillColor:(UIColor *)fillColor {

[self drawCircleFrame:CGRectMake(center.x - radius, center.y - radius, radius * 2, radius * 2) fillColor:fillColor];

}

//画饼

+ (void)drawCakeCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle {

[self drawCakeCenter:circleCenter radius:radius startAngle:startAngle endAngle:endAngle clockwise:0 color:kBlackColor];

}

+ (void)drawCakeCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle color:(UIColor *)color {

[self drawCakeCenter:circleCenter radius:radius startAngle:startAngle endAngle:endAngle clockwise:0 color:color];

}

+ (void)drawCakeCenter:(CGPoint)circleCenter radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle  clockwise:(int)clockwise color:(UIColor *)color {

CGContextRef    ref = UIGraphicsGetCurrentContext();

CGContextMoveToPoint(ref, circleCenter.x, circleCenter.y);

CGContextAddArc(ref, circleCenter.x, circleCenter.y,radius, startAngle, endAngle, clockwise);

CGContextClosePath(ref);

if (color) {

[color set];

}

CGContextFillPath(ref);

}

//字符串

//默认字体:40 颜色:黑色 位置:屏幕中心

+ (void)drawString:(NSString *)str {

[self drawString:str center:CGPointMake(kSCREEN_WIDTH * 0.5, kSCREEN_HEIGHT * 0.5)];

}

//location

+ (void)drawString:(NSString *)str center:(CGPoint)center {

[self drawString:str center:center font:kFontWithSize_40];

}

+ (void)drawString:(NSString *)str rect:(CGRect)rect {

[self drawString:str rect:rect font:kFontWithSize_40];

}

//font

+ (void)drawString:(NSString *)str font:(UIFont *)font {

[self drawString:str center:CGPointMake(kSCREEN_WIDTH * 0.5, kSCREEN_HEIGHT * 0.5) font:font];

}

+ (void)drawString:(NSString *)str center:(CGPoint)center font:(UIFont *)font {

[self drawString:str center:center font:font color:kBlueColor];

}

+ (void)drawString:(NSString *)str rect:(CGRect)rect font:(UIFont *)font {

[self drawString:str rect:rect font:font color:kBlueColor];

}

//color

+ (void)drawString:(NSString *)str color:(UIColor *)color {

[self drawString:str center:CGPointMake(kSCREEN_WIDTH * 0.5, kSCREEN_HEIGHT * 0.5) color:color];

}

+ (void)drawString:(NSString *)str center:(CGPoint)center color:(UIColor *)color {

[self drawString:str center:center font:kFontWithSize_40 color:color];

}

+ (void)drawString:(NSString *)str rect:(CGRect)rect color:(UIColor *)color {

[self drawString:str rect:rect font:kFontWithSize_40 color:color];

}

+ (void)drawString:(NSString *)str center:(CGPoint)center font:(UIFont *)font color:(UIColor *)color {

CGRect  strRect = [str boundingRectWithSize:CGSizeMake(kSCREEN_WIDTH, kSCREEN_HEIGHT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil];

[str drawAtPoint:CGPointMake(center.x - strRect.size.width * 0.5, center.y - strRect.size.height * 0.5) withAttributes:@{NSFontAttributeName:font,NSForegroundColorAttributeName:color}];

}

+ (void)drawString:(NSString *)str rect:(CGRect)rect font:(UIFont *)font color:(UIColor *)color {

[str drawInRect:rect withAttributes:@{NSFontAttributeName:font,NSForegroundColorAttributeName:color}];

}

//图片

+ (void)drawImage:(UIImage *)image {

[self drawImage:image center:CGPointMake(kSCREEN_WIDTH * 0.5, kSCREEN_HEIGHT * 0.5)];

}

+ (void)drawImage:(UIImage *)image center:(CGPoint)center {

[self drawImage:image point:CGPointMake(center.x - image.size.width * 0.5, center.y - image.size.height * 0.5)];

}

+ (void)drawImage:(UIImage *)image point:(CGPoint)point {

[image drawAtPoint:point];

}

+ (void)drawImage:(UIImage *)image rect:(CGRect)rect {

[image drawInRect:rect];

}

//旋转角度

+ (void)drawImage:(UIImage *)image center:(CGPoint)center angle:(CGFloat)angle {

[self drawImage:image center:center translate:CGPointMake(center.x, center.y) angle:angle];

}

+ (void)drawImage:(UIImage *)image point:(CGPoint)point angle:(CGFloat)angle {

[self drawImage:image point:point translate:CGPointMake(point.x + image.size.width * 0.5, point.y + image.size.height * 0.5) angle:angle];

}

+ (void)drawImage:(UIImage *)image rect:(CGRect)rect angle:(CGFloat)angle {

[self drawImage:image rect:rect translate:CGPointMake(rect.origin.x + rect.size.width * 0.5, rect.origin.y + rect.size.height * 0.5) angle:angle];

}

//设置旋转点

+ (void)drawImage:(UIImage *)image center:(CGPoint)center translate:(CGPoint)translate angle:(CGFloat)angle {

CGContextRef    ref = UIGraphicsGetCurrentContext();

CGContextSaveGState(ref);

//设置旋转点

CGContextTranslateCTM(ref, translate.x, translate.y);

//旋转

CGContextRotateCTM(ref, kAngle(angle));

[self drawImage:image center:center];

}

+ (void)drawImage:(UIImage *)image point:(CGPoint)point translate:(CGPoint)translate angle:(CGFloat)angle {

CGContextRef    ref = UIGraphicsGetCurrentContext();

CGContextSaveGState(ref);

//设置旋转点

CGContextTranslateCTM(ref, translate.x, translate.y);

//旋转

CGContextRotateCTM(ref, kAngle(angle));

[self drawImage:image point:point];

}

+ (void)drawImage:(UIImage *)image rect:(CGRect)rect translate:(CGPoint)translate angle:(CGFloat)angle {

CGContextRef    ref = UIGraphicsGetCurrentContext();

CGContextSaveGState(ref);

//设置旋转点

CGContextTranslateCTM(ref, translate.x, translate.y);

//旋转

CGContextRotateCTM(ref, kAngle(angle));

[self drawImage:image rect:rect];

}

谢谢阅读!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 214,233评论 6 495
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,357评论 3 389
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,831评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,313评论 1 288
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,417评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,470评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,482评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,265评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,708评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,997评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,176评论 1 342
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,827评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,503评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,150评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,391评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,034评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,063评论 2 352

推荐阅读更多精彩内容