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?
2
- I answered below, but why would you not want to override drawRect?picciano– picciano2012-02-22 20:40:58 +00:00Commented Feb 22, 2012 at 20:40
- because it would be annoying to just have a UIImage class with a drawRect on it?adit– adit2012-02-22 22:07:32 +00:00Commented Feb 22, 2012 at 22:07
Add a comment |
2 Answers
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); 1 Comment
beryllium
@adit, I don't know what is your imageview name. It's just a common example.