0

I have a UIView whose backgroundColor is UIColor.clear. I need to perform drawRect in a subrectangle within the bounds of this view but also want to set the background color of that subrect to be black color with 0.5 transparency. I need to always invoke drawRect on that subrect whenever I want. How do I do that?

Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131

1 Answers1

0

According to the documentation, you don't invoke drawRect: directly, but to redraw the view (i.e. set or unset your black background colour), you call setNeedsDisplay on the view which will invoke drawRect on the next draw cycle.

This will allow you to set your black background and draw whatever else you want in there, but I'm pretty sure a view can't have different alpha values for different subregions. For the alpha, this might be what you're looking for.

Dalton Sweeney
  • 1,108
  • 3
  • 11
  • 24