開始点がUILabelの場合に線を引きたいiPhoneアプリケーションで作業していますが、タッチされているテキストを検出したいのですが、どうすればよいですか? 助けてください。よろしくお願いします。線を引くためのコードは次のとおりです。このコードを使用すると、線を引くことができますが、ラベルから線を引きたいです。
- (CAShapeLayer *)createShapeLayer:(UIView *)view
{
CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
shapeLayer.fillColor = [UIColor clearColor].CGColor;
shapeLayer.strokeColor = [UIColor redColor].CGColor;
shapeLayer.lineWidth = 5.0;
[view.layer addSublayer:shapeLayer];
return shapeLayer;
}
- (void)handlePanGesture:(UIPanGestureRecognizer *)gesture
{
static CAShapeLayer *shapeLayer;
static CGPoint origin;
if (gesture.state == UIGestureRecognizerStateBegan)
{
shapeLayer = [self createShapeLayer:gesture.view];
origin = [gesture locationInView:gesture.view];
NSLog(@"cgpoint %f and y %f",origin.x,origin.y);
}
else if (gesture.state == UIGestureRecognizerStateChanged)
{
UIBezierPath *path1 = [UIBezierPath bezierPath];
[path1 moveToPoint:origin];
CGPoint location = [gesture locationInView:gesture.view];
[path1 addLineToPoint:location];
shapeLayer.path = path1.CGPath;
}
else if (gesture.state == UIGestureRecognizerStateEnded ||
gesture.state == UIGestureRecognizerStateFailed ||
gesture.state == UIGestureRecognizerStateCancelled)
{
shapeLayer = nil;
}
}