三角形

用CGContextRef画各种图形(文字、圆、直线、弧线、矩形、扇形、椭圆、三角形、圆角矩形

无人久伴 提交于 2020-03-01 17:13:03
首先了解一下CGContextRef: An opaque type that represents a Quartz 2D drawing environment. Graphics Context是图形上下文,可以将其理解为一块画布,我们可以在上面进行绘画操作,绘制完成后,将画布放到我们的view中显示即可,view看作是一个画框. 自己学习时实现的demo,希望对大家有帮助,具体的实现看代码,并有完美的注释解释,还有一些对我帮助的博文供大家参考。都在代码里面。 看一下demo效果图先: 自定义CustomView类,CustomView.h: [cpp] view plain copy #import <UIKit/UIKit.h> #import <QuartzCore/QuartzCore.h> #define PI 3.14159265358979323846 @interface CustomView : UIView @end 实现类CustomView.m: [cpp] view plain copy #import "CustomView.h" @implementation CustomView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) {