iOS 简单的使用drawRect 绘制

1 。首先新建UIView一个类

2 在UIView一个类.m 里面追加

- (instancetype)initWithFrame:(CGRect)frame{

self = [super initWithFrame:frame];
if (self) {
self.clearsContextBeforeDrawing = YES;
}
return self;
}
- (void)drawRect:(CGRect)rect {
[self drawCurve]; // 绘制心电图型
[self drawGrid]; //绘制心电图 背景网格
}
- (void)drawGrid{}

- (void)drawCurve{}

 

 

注意在从新绘制画图时

  CGContextRef context = UIGraphicsGetCurrentContext();//获取上下文 知道你要画图的地方 (就是画布)

只有放在- (instancetype)initWithFrame:(CGRect)frame{ 里面才是好用的

3 之后在你的主画面里面引用

 

 最后运行效果

 

posted @ 2017-09-22 16:36  懒猫口米  阅读(537)  评论(0编辑  收藏  举报