1

how can i add an X looking red stroke to a UIImageView.

i would like to add 2 diagonal red lines to a UIImageView, is there a way to do it programmatically using layers or masks? (not in drawRect)

David Ben Ari
  • 2,259
  • 3
  • 21
  • 40
  • Why not in drawRect which is where all drawing should be done? – ericg Feb 24 '13 at 12:28
  • Could you simply create another UIView at the same size and location of the one you wanted to add the red X over, have it draw the red X in it's drawRect (or just have it draw a scaled UIImage of a red X), and then make it visible and on top of your UIImageView? – ericg Feb 24 '13 at 12:32
  • 1
    @ericgorr uiimageview doesn't call drawRect, to answer your first comment – jrturton Feb 24 '13 at 12:37
  • @ericgorr, i like your suggestion in your second comment, if you write it as an answer and throw a bit of the drawRect code i'll accept it.. – David Ben Ari Feb 24 '13 at 12:44

1 Answers1

1

Use a CAShapeLayer with your X shape as its path. Depending on how you've drawn the path, you may want to set a nil fill colour (since a path just made of two crossed lines should not be filled).

Add the shape layer as a sublayer of your image view.

jrturton
  • 118,105
  • 32
  • 252
  • 268