一个使用UIBezierPath搭配UIImage做的简易画板

效果图

拥有的功能:
1、每条线段不同颜色
2、橡皮擦
3、撤回/清屏/重绘
4、外部传入参数绘制(场景:使用即时通信同步画画界面)

核心代码:

- (void)drawRect:(CGRect)rect {
    
    if (self.drawResult) {
        [self.drawResult drawInRect:self.bounds];
    }
    
    if (self.currentPath) {
        if (self.isEraser) {
            [self.currentPath strokeWithBlendMode:kCGBlendModeClear alpha:1.0];
            [UIColor.clearColor setStroke];
        } else {
            [self.currentPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
            [self.lineColor setStroke];
        }
        [self.currentPath stroke];
    }
    
}

码云

有问题和想法的可以评论我。

你可能感兴趣的:(一个使用UIBezierPath搭配UIImage做的简易画板)