I need to draw a horizontal line in a UIView. What is the easiest way to do it. For example, I want to draw a black horizontal line at y-coord=200.
I am NOT using Interface Builder.
Maybe this is a bit late, but I want to add that there is a better way. Using UIView is simple, but relatively slow. This method overrides how the view draws itself and is faster:
- (void)drawRect:(CGRect)rect {     [super drawRect:rect];      CGContextRef context = UIGraphicsGetCurrentContext();     CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);      // Draw them with a 2.0 stroke width so they are a bit more visible.     CGContextSetLineWidth(context, 2.0f);      CGContextMoveToPoint(context, 0.0f, 0.0f); //start at this point      CGContextAddLineToPoint(context, 20.0f, 20.0f); //draw to this point      // and now draw the Path!     CGContextStrokePath(context); } 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With