adit
adit

Reputation: 33674

drawing a line from a UIViewController

I have a UIViewController which has a UIImageView. I wanted to draw a line on top of the UIImageView. I know that in order to do this I have to override the drawRect in a UIView. Is there an alternative to this?

Upvotes: 0

Views: 1549

Answers (2)

beryllium
beryllium

Reputation: 29767

Something like this:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGContextSetLineWidth(context, 1.0f);
CGContextMoveToPoint(context, 0, 0); 
CGContextAddLineToPoint(context, view.frame.size.width, view.frame.size.height);
CGContextStrokePath(context);

Upvotes: 1

picciano
picciano

Reputation: 22711

While overriding drawRect may be the best solution, there are always alternatives.

If the line is horizontal or vertical, you could create a UIView with the frame of the line you need and set its background color.

You could overlay an image of the line, rotated/resized as needed.

Upvotes: 0

Related Questions