For me the best way to approach this is create UIView's as lines. If they are simply lines with plain colors just use the background view and set the CGRectFrame accordingly.
In order to react to touch event's without dealing with positions etc, create a touchEvent in the init method of the UIView like this:
UITapGestureRecognizer *onTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lineClicked)];
[self addGestureRecognizer:onTap];
Declare the function inside the UIView class:
-(void)lineClicked {
//You can check some @property here to know what line was clicked for example
if (self.color == [UIColor blackColor])
//do something
else
//do another thing
// You can use a custom protocol to tell the ViewController that a click happened
(**) if ([self.delegate respondsToSelector:@selector(lineWasClicked:)]) {
[self.delegate lineWasClicked:self];
}
}
(**) You will probably want to put some logic into your viewController after clicking in the line. The best way to approach this is to declare a @protocol in your CustomUIView.h file and pass self as parameter so the viewController knows who was clicked:
@protocol LineClikedDelegate <NSObject>
@optional
- (void)lineWasClicked:(UIView *)line; //fired when clicking in the line
@end
Finally, create a @property in your CustomUIView to point the delegate:
@property id<DisclosureDelegate> delegate;
And in the ViewController. When you create lines as UIViews set the delegate like:
blackLine.delegate = self.
Implement the method - (void)lineWasClicked:(UIView *)line;
in the ViewController and you are set.