iOS 簡單的使用drawRect 繪制
阿新 • • 發佈:2017-09-22
ima com () sel elf etc 簡單 text csg
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 之後在你的主畫面裏面引用
最後運行效果
iOS 簡單的使用drawRect 繪制