ZWGraphicView
簽名涂鴉畫板
功能
實(shí)際開發(fā)中主要用于手寫簽名及其它繪畫涂鴉刃鳄,最終生成圖片畦韭,用于上傳服務(wù)器事示。
文件結(jié)構(gòu)
ZWGraphicView.h 和 ZWGraphicView.m兩個(gè)文件黍判。
ZWGraphicView.h的代碼如下:
@interface ZWGraphicView : UIView
{
CGPoint _start;//起始點(diǎn)
CGPoint _move;//移動(dòng)點(diǎn)
CGMutablePathRef _path;//路徑
NSMutableArray * _pathArray;//保存路徑信息
CGFloat _lineWidth;//線寬
UIColor * _lineColor;//線的顏色
BOOL _isDrawLine;//是否有畫線
}
/**
* 線寬
*/
@property (nonatomic,assign) CGFloat lineWidth;
/**
* 線的顏色
*/
@property (nonatomic,strong) UIColor * lineColor;
/**
* 畫線路徑
*/
@property (nonatomic,strong) NSMutableArray * pathArray;
/**
* 獲取畫圖
*/
-(UIImage*)getDrawingImg;
/**
* 清空畫板
*/
-(void)clearDrawBoard;
/**
* 撤銷上一次操作
*/
-(void)undoLastDraw;
/**
* 保存圖像至相冊(cè)
*/
-(void)savePhotoToAlbum;
用法
import "ZWGraphicView.h"引入頭文件
- (void)viewDidLoad {
[super viewDidLoad];
ZWGraphicView * drawView = [[ZWGraphicView alloc] initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, self.view.bounds.size.height-100)];
self.graphicView = drawView;
[self.view addSubview:drawView];
}
- (IBAction)savePhoto:(id)sender {
[self.graphicView savePhotoToAlbum];
}
- (IBAction)undo:(id)sender {
[self.graphicView undoLastDraw];
}
- (IBAction)clearAll:(id)sender {
[self.graphicView clearDrawBoard];
}
演示效果
demo演示.gif