封装CoreGraphics的API简化绘图操作
2023-09-14 08:57:16 时间
- (void)drawStrokeBlock:(CGContextObjectDrawBlock_t)block closePath:(BOOL)closePath;
* 填充区域用block (beginPath + closePath + 你绘制的代码 + fillPath)
* @param block 绘制用block
* @param closePath 是否关闭曲线
- (void)drawFillBlock:(CGContextObjectDrawBlock_t)block closePath:(BOOL)closePath;
* 绘制加填充
* @param block 绘制用block
* @param closePath 是否关闭曲线
- (void)drawStrokeAndFillBlock:(CGContextObjectDrawBlock_t)block closePath:(BOOL)closePath;
#pragma mark - 绘制图片API
- (void)drawImage:(UIImage *)image atPoint:(CGPoint)point;
- (void)drawImage:(UIImage *)image atPoint:(CGPoint)point blendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha;
- (void)drawImage:(UIImage *)image inRect:(CGRect)rect;
- (void)drawImage:(UIImage *)image inRect:(CGRect)rect blendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha;
- (void)drawImage:(UIImage *)image asPatternInRect:(CGRect)rect;
#pragma mark - 保存操作
* 将当前设置存取到栈区中(入栈操作)
- (void)saveStateToStack;
* 从栈区中取出之前保存的设置(出栈操作)
- (void)restoreStateFromStack;
#pragma mark - 图形绘制API
* 移动到起始点
* @param point 起始点
- (void)moveToStartPoint:(CGPoint)point;
* 添加一个点(与上一个点直线相连)
* @param point 点
- (void)addLineToPoint:(CGPoint)point;
* 添加二次贝塞尔曲线
* @param point 结束点
* @param pointOne 控制点1
* @param pointTwo 控制点2
- (void)addCurveToPoint:(CGPoint)point controlPointOne:(CGPoint)pointOne controlPointTwo:(CGPoint)pointTwo;
* 添加一次贝塞尔曲线
* @param point 结束点
* @param controlPoint 控制点
- (void)addQuadCurveToPoint:(CGPoint)point controlPoint:(CGPoint)controlPoint;
* 在指定的区域填充彩色的矩形(此为直接绘制)
* @param rect 指定的区域
* @param gradientColor 渐变色对象
- (void)drawLinearGradientAtClipToRect:(CGRect)rect gradientColor:(GradientColor *)gradientColor;
#pragma mark -
* 添加一个矩形
* @param rect
- (void)addRect:(CGRect)rect;
* 在给定的矩形中绘制椭圆
* @param rect
- (void)addEllipseInRect:(CGRect)rect;
* 将string绘制在指定的点上
* @param string 字符串
* @param point 点
* @param attributes 富文本设置(可以为空)
- (void)drawString:(NSString *)string atPoint:(CGPoint)point withAttributes:(NSDictionary *)attributes;
* 将string绘制在制定的区域
* @param string 字符串
* @param rect 区域
* @param attributes 富文本设置(可以为空)
- (void)drawString:(NSString *)string inRect:(CGRect)rect withAttributes:(NSDictionary *)attributes;
* 将富文本绘制在制定的点上
* @param string 富文本
* @param point 点
- (void)drawAttributedString:(NSAttributedString *)string atPoint:(CGPoint)point;
* 将富文本绘制在制定的矩形中
* @param string 富文本
* @param rect 矩形
- (void)drawAttributedString:(NSAttributedString *)string inRect:(CGRect)rect;
@end
前端pua: JSON API还有二次封装的必要吗? JSON 是 JavaScript Object Notation 的缩写,最初是被设计为 JavaScript 的一个子集,因其和编程语言无关,所以成为了一种开放标准的常见数据格式。虽然 JSON 是源自于JavaScript,但到目前很多编程语言都有了 JSON 解析的库,如 C、Java、Python 等。
干货 | 通用 api 封装实战,带你深入理解 PO 在普通的接口自动化测试中,如果接口的参数,比如 url,headers等传参改变,或者测试用例的逻辑、断言改变,那么整个测试代码都需要改变。apiobject设计模式借鉴了pageobject的设计模式,可以实现一个优雅、强大的接口测试框架。
apiobject设计模式可以简单分为6个模块,分别是API对象、接口测试框架、配置模块、数据封装、Utils、测试用例。 - 接口测试框架:ba
// // CGContextObject.m // DrawRect // Created by YouXianMing on 15/7/2. // Copyright (c) 2015年 YouXianMing. All rights reserved. #import "CGContextObject.h" @interface CGContextObject () @implementation CGContextObject - (instancetype)initWithCGContext:(CGContextRef)context { self = [super init]; if (self) { self.context = context; return self; - (void)moveToStartPoint:(CGPoint)point { if (_context) { CGContextMoveToPoint(_context, point.x, point.y); - (void)addLineToPoint:(CGPoint)point { if (_context) { CGContextAddLineToPoint(_context, point.x, point.y); - (void)addCurveToPoint:(CGPoint)point controlPointOne:(CGPoint)pointOne controlPointTwo:(CGPoint)pointTwo { if (_context) { CGContextAddCurveToPoint(_context, pointOne.x, pointOne.y, pointTwo.x, pointTwo.y, point.x, point.y); - (void)addQuadCurveToPoint:(CGPoint)point controlPoint:(CGPoint)controlPoint { if (_context) { CGContextAddQuadCurveToPoint(_context, controlPoint.x, controlPoint.y, point.x, point.y); - (void)drawLinearGradientAtClipToRect:(CGRect)rect gradientColor:(GradientColor *)gradientColor { [self saveStateToStack];
gradientColor.gradientStartPoint, gradientColor.gradientEndPoint, kCGGradientDrawsBeforeStartLocation);
- (void)drawString:(NSString *)string atPoint:(CGPoint)point withAttributes:(NSDictionary *)attributes { [string drawAtPoint:point withAttributes:attributes]; - (void)drawString:(NSString *)string inRect:(CGRect)rect withAttributes:(NSDictionary *)attributes { [string drawInRect:rect withAttributes:attributes]; - (void)drawAttributedString:(NSAttributedString *)string atPoint:(CGPoint)point { [string drawAtPoint:point]; - (void)drawAttributedString:(NSAttributedString *)string inRect:(CGRect)rect { [string drawInRect:rect]; - (void)beginPath { if (_context) { CGContextBeginPath(_context); - (void)closePath { if (_context) { CGContextClosePath(_context); - (void)strokePath { if (_context) { CGContextStrokePath(_context); - (void)fillPath { if (_context) { CGContextFillPath(_context); - (void)strokeAndFillPath { if (_context) { CGContextDrawPath(_context, kCGPathFillStroke); - (void)drawStrokeBlock:(CGContextObjectDrawBlock_t)block { [self beginPath]; __weak CGContextObject *weakSelf = self; block(weakSelf); [self closePath]; [self strokePath]; - (void)drawFillBlock:(CGContextObjectDrawBlock_t)block { [self beginPath]; __weak CGContextObject *weakSelf = self; block(weakSelf); [self closePath]; [self fillPath]; - (void)drawStrokeAndFillBlock:(CGContextObjectDrawBlock_t)block { [self beginPath]; __weak CGContextObject *weakSelf = self; block(weakSelf); [self closePath]; [self strokeAndFillPath]; - (void)drawStrokeBlock:(CGContextObjectDrawBlock_t)block closePath:(BOOL)closePath { [self beginPath]; __weak CGContextObject *weakSelf = self; block(weakSelf); if (closePath) { [self closePath]; [self strokePath]; - (void)drawFillBlock:(CGContextObjectDrawBlock_t)block closePath:(BOOL)closePath { [self beginPath]; __weak CGContextObject *weakSelf = self; block(weakSelf); if (closePath) { [self closePath]; [self fillPath]; - (void)drawStrokeAndFillBlock:(CGContextObjectDrawBlock_t)block closePath:(BOOL)closePath { [self beginPath]; __weak CGContextObject *weakSelf = self; block(weakSelf); if (closePath) { [self closePath]; [self strokeAndFillPath]; - (void)drawImage:(UIImage *)image atPoint:(CGPoint)point { [image drawAtPoint:point]; - (void)drawImage:(UIImage *)image atPoint:(CGPoint)point blendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha { [image drawAtPoint:point blendMode:blendMode alpha:alpha]; - (void)drawImage:(UIImage *)image inRect:(CGRect)rect { [image drawInRect:rect]; - (void)drawImage:(UIImage *)image inRect:(CGRect)rect blendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha { [image drawInRect:rect blendMode:blendMode alpha:alpha]; - (void)drawImage:(UIImage *)image asPatternInRect:(CGRect)rect { [image drawAsPatternInRect:rect]; - (void)saveStateToStack { if (_context) { CGContextSaveGState(_context); - (void)restoreStateFromStack { if (_context) { CGContextRestoreGState(_context); #pragma mark - 重写setter,getter方法 @synthesize strokeColor = _strokeColor; - (void)setStrokeColor:(RGBColor *)strokeColor { if (_context) { _strokeColor = strokeColor; CGContextSetRGBStrokeColor(_context, strokeColor.red, strokeColor.green, strokeColor.blue, strokeColor.alpha); - (RGBColor *)strokeColor { return _strokeColor; @synthesize fillColor = _fillColor; - (void)setFillColor:(RGBColor *)fillColor { if (_context) { _fillColor = fillColor; CGContextSetRGBFillColor(_context, fillColor.red, fillColor.green, fillColor.blue, fillColor.alpha); - (RGBColor *)fillColor { return _fillColor; @synthesize lineWidth = _lineWidth; - (void)setLineWidth:(CGFloat)lineWidth { if (_context) { _lineWidth = lineWidth; CGContextSetLineWidth(_context, lineWidth); - (CGFloat)lineWidth { return _lineWidth; @synthesize lineCap = _lineCap; - (void)setLineCap:(CGLineCap)lineCap { if (_context) { _lineCap = lineCap; CGContextSetLineCap(_context, lineCap); - (CGLineCap)lineCap { return _lineCap; @end
细节
前端pua: JSON API还有二次封装的必要吗? JSON 是 JavaScript Object Notation 的缩写,最初是被设计为 JavaScript 的一个子集,因其和编程语言无关,所以成为了一种开放标准的常见数据格式。虽然 JSON 是源自于JavaScript,但到目前很多编程语言都有了 JSON 解析的库,如 C、Java、Python 等。
干货 | 通用 api 封装实战,带你深入理解 PO 在普通的接口自动化测试中,如果接口的参数,比如 url,headers等传参改变,或者测试用例的逻辑、断言改变,那么整个测试代码都需要改变。apiobject设计模式借鉴了pageobject的设计模式,可以实现一个优雅、强大的接口测试框架。
apiobject设计模式可以简单分为6个模块,分别是API对象、接口测试框架、配置模块、数据封装、Utils、测试用例。 - 接口测试框架:ba
相关文章
- Android基于DataBinding封装RecyclerView实现快速列表开发
- Python机器学习教程—回归模型的评估与封装
- POI读取Excel自动封装JavaBean
- 原生微信小程序flyio封装多baseURL配置请求,如同axios一样非常爽利的使用api
- API和Web Api
- 开箱即用!Node.js+Mysql模块封装
- Python 封装zabbix-get接口
- BJCORE半导体划片机设备——封装的八道工序
- 阿里云短信服务验证码封装类 v1.0.0【flc/dysms】
- 自己封装的Java excel数据读取方法详解编程语言
- 使用MySQL函数API实现数据库操作(mysql函数api)
- Mysql JDBC封装:最佳数据库接口实现(mysqljdbc封装)
- 探索Linux驱动API:开启发展之路(linux驱动api)
- MySQL的API接口:快速、便捷的数据库访问方式(mysql的api接口)
- 从零开始:Linux ISO封装技术详解(linux系统封装iso)
- MySQL C语言API应用注意事项(mysqlc语言api)
- API接入MySQL,为数据开辟新通道(api链接MySQL)
- 妙用API连接Oracle,轻松实现跨平台连接(api连oracle)
- 深入学习如何封装Redis工具类(如何封装redis工具类)
- 如何使用MySQL下载API数据(mysql下载api数据)
- 深入解析Redis集群API的运用(redis集群的api)
- 研究Oracle API接口,助推业务发展(oracle api接口)
- 优化红色闪电 API优化加快网站速度(redis 网站api)
- 从零学python系列之浅谈pickle模块封装和拆封数据对象的方法