1

I use CGContext in a subclass of UIView to draw lines, it works fine when no other views in the ViewController on storyboard. However each time putting in an `UIImageView' with an image, it'd cover parts of the lines.

But I wanna draw several lines inside the UIImageView or inside the image. What should I do?

Would someone help me with it?

S.P.K
  • 13
  • 4
  • Found this answer looking around for something similar: http://stackoverflow.com/questions/25229916/how-to-procedurally-draw-rectangle-lines-in-swift-using-cgcontext – August Jan 23 '17 at 19:56
  • Look here for drawing lines on a image in an image view: [Draw line in UIImage](https://stackoverflow.com/questions/29402902/ios-swift-draw-line-on-uiimage-to-save-to-file) – D. Rothschild Mar 21 '18 at 17:55

1 Answers1

1

You cannot modify the drawing of an image view. If you want lines to appear in an image view, you must modify the image that it contains. Make a new image context, draw the image into it, draw the lines, extract the new image, and assign that image to the image view.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • would you give an example in swift how to draw lines into a UIImage. Thanks. – Ismail Oct 09 '15 at 10:16
  • Read what I said, please. You don't draw lines into a UIImage. You draw into an image graphics context and extract the image. – matt Oct 09 '15 at 14:57