0

I want to draw lines which is shown in the image. enter image description here

and I have to add four labels with name Section 1,Section 2,Section 3,Section 4.

I have tried below code to draw lines and it works

-(UIBezierPath*)createBezierPathWithMoveToPoint:(CGPoint)moveToPoint andlineToPoint:(CGPoint)toPoint
{
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:moveToPoint];
    [path addLineToPoint:toPoint];
    return path;
}

-(CAShapeLayer*)createLayerWithPath:(CGPathRef)path strokColor:(UIColor *)colorStroke lineWidth:(CGFloat)width fillColor:(UIColor *)colorFill
{

    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.path = path;
    layer.strokeColor = [colorStroke CGColor];
    layer.lineWidth = width;
    layer.fillColor = [colorFill CGColor];
    return layer;

}

By using above code I have achieved lines and I have added for UIlabel's manually. Can anyone please help me to get action like UIButton actions, when user touch in between these sections. ?

OR

If there is any best and easiest way to achieve this please let me know.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Mani murugan
  • 1,792
  • 2
  • 17
  • 32
  • Use UITapgesture. – El Tomato Jul 05 '17 at 06:41
  • @ElTomato To which view I will have to add Tap gesture ? Because these are all lines.. how can I check that touch point is between to lines ? – Mani murugan Jul 05 '17 at 06:52
  • Add a recognizer to each label. – El Tomato Jul 05 '17 at 07:36
  • @ElTomato Thanks Tomato. But I need to get touch action anywhere in between two lines.. not on labels.. – Mani murugan Jul 05 '17 at 08:45
  • 1
    That's more a Maths/geometry problem than a iOS (specific one). Since you draw yourself the lines, you can have the intersection point. Then looking for solutions like this one: https://stackoverflow.com/questions/2049582/how-to-determine-if-a-point-is-in-a-2d-triangle or https://math.stackexchange.com/questions/51326/determining-if-an-arbitrary-point-lies-inside-a-triangle-defined-by-three-points could help you. – Larme Jul 05 '17 at 09:03
  • 1
    Then create each object with UIBezierPath. – El Tomato Jul 05 '17 at 10:16

0 Answers0