Comment find une zone incolore uibeizerpath?

entrez la description de l'image ici

Cette couleur grise est UIImageView et la police de couleur blanche est Image.

Cette image est placée dans UIImageView.

J'aime colorer seulement dans la police, pas une UIImageview entière pour que je vais find les coordonnées de l'image.

je suis nouveau à ce genre de concept si gentiment quelqu'un me guide comment colorer seulement à l'intérieur de l'image, il y a plus de 50 images est là, ce n'est pas statique donc donnez une bonne idée.

C'est le code que j'utilise pour dessiner à l'intérieur de UIImageView:

-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; touchPoint = [touch locationInView:self.imgColor]; UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:CGPointMake(touchPoint.x,touchPoint.y)]; [path addLineToPoint:CGPointMake(startingPoint.x,startingPoint.y)]; startingPoint=touchPoint; CAShapeLayer *shapeLayer = [CAShapeLayer layer]; shapeLayer.path = [path CGPath]; shapeLayer.strokeColor = [[UIColor blueColor] CGColor]; shapeLayer.lineWidth = 3.0; shapeLayer.fillColor = [[UIColor redColor] CGColor]; [self.imgColor.layer addSublayer:shapeLayer]; [arrLayer addObject:shapeLayer]; NSLog(@"Touch moving point =x : %f Touch moving point =y : %f", touchPoint.x, touchPoint.y); } 

Utilisez cette vue UIImage personnalisée: Capture d'écran du code de travail

CustomView.h

 @interface CustomView : UIImageView @end 

CustomView.m

 @interface CustomView () { CGPoint touchPoint,startingPoint; UIView *drawingView; } @end @implementation CustomView -(void)awakeFromNib { drawingView = [[UIView alloc] initWithFrame:self.bounds]; drawingView.backgroundColor = [UIColor clearColor]; [self addSubview:drawingView]; [self updateMask]; } - (void)updateMask { CALayer *maskLayer = [CALayer layer]; maskLayer.geometryFlipped = YES; maskLayer.contents = (id)self.image.CGImage; switch (self.contentMode) { case UIViewContentModeScaleToFill: maskLayer.contentsGravity = kCAGravityResize; break; case UIViewContentModeScaleAspectFit: maskLayer.contentsGravity = kCAGravityResizeAspect; break; case UIViewContentModeScaleAspectFill: maskLayer.contentsGravity = kCAGravityResizeAspectFill; break; case UIViewContentModeCenter: maskLayer.contentsGravity = kCAGravityCenter; break; case UIViewContentModeTop: maskLayer.contentsGravity = kCAGravityTop; break; case UIViewContentModeBottom: maskLayer.contentsGravity = kCAGravityBottom; break; case UIViewContentModeLeft: maskLayer.contentsGravity = kCAGravityLeft; break; case UIViewContentModeRight: maskLayer.contentsGravity = kCAGravityRight; break; case UIViewContentModeTopLeft: maskLayer.contentsGravity = kCAGravityTopLeft; break; case UIViewContentModeTopRight: maskLayer.contentsGravity = kCAGravityTopRight; break; case UIViewContentModeBottomLeft: maskLayer.contentsGravity = kCAGravityBottomLeft; break; case UIViewContentModeBottomRight: maskLayer.contentsGravity = kCAGravityBottomRight; break; default: break; } maskLayer.frame = drawingView.bounds; drawingView.layer.mask = maskLayer; } - (void)setImage:(UIImage *)image { [super setImage:image]; [self updateMask]; } - (void)layoutSubviews { [super layoutSubviews]; drawingView.frame = self.bounds; drawingView.layer.mask.frame = drawingView.bounds; } -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; touchPoint = [touch locationInView:self]; if (!CGPointEqualToPoint(startingPoint, CGPointZero)) { UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:CGPointMake(touchPoint.x,touchPoint.y)]; [path addLineToPoint:CGPointMake(startingPoint.x,startingPoint.y)]; CAShapeLayer *shapeLayer = [CAShapeLayer layer]; shapeLayer.path = [path CGPath]; shapeLayer.strokeColor = [[UIColor blueColor] CGColor]; shapeLayer.lineWidth = 3.0; shapeLayer.fillColor = [[UIColor redColor] CGColor]; [drawingView.layer addSublayer:shapeLayer]; } startingPoint=touchPoint; // [arrLayer addObject:shapeLayer]; NSLog(@"Touch moving point =x : %f Touch moving point =y : %f", touchPoint.x, touchPoint.y); } - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event; { startingPoint = CGPointZero; } @end