title: Negative text color with respect to background image
body: <p>I'm trying to subclass (because thats probably the easiest way to do it) UILabel so it's <strong>text</strong> color is negative to the part of the background image it overlays. I also have an approximate idea how to do that, but cannot transform it into code.</p>
  
  <p><img src="https://i.stack.imgur.com/BlHKy.jpg" alt="Figure 1"></p>
  
  <h2>Parameters to pass the subclass</h2>
  
  <ul>
  <li>Background image</li>
  <li>Position of the UILabel within the background image (probably CGRect as it needs to know the x, y, w, h of the background image the UILabel will cover) - this could also be just the UILabel's rect, as the UILabel will be the subview of an UIImageView containing the background image.</li>
  </ul>
  
  <h2>Logic while drawing the label</h2>
  
  <ol>
  <li>Create a mask with the text - the content of the mask would only be the text itself, not the background.</li>
  <li>Crop out the specific part (rect) of the Background image which is overlaid by the label.</li>
  <li>Delete (or make transparent) all of the image outside the text mask -> that way you would only be left with the image where the text is, the rest would be gone.</li>
  <li>Invert the image's colors (with <a href="https://stackoverflow.com/questions/6672517/is-programmatically-inverting-the-colors-of-an-image-possible">this</a> method probably) or use <code>kCGBlendModeDifference</code> in some way perhaps?</li>
  <li>Draw all that in one of the methods UILabel's <code>drawRect</code> or <code>drawTextInRect</code> methods.</li>
  </ol>
  
  <h2>Usage</h2>
  
  <p>The usage of this would probably be something like</p>
  
  <ol>
  <li>Alloc an <code>UIImage</code></li>
  <li>Display it in an <code>UIImageView</code></li>
  <li>Create the <code>UILabel</code> subclass with the inverted text color relative to the part of the image the <code>UILabel</code> will be placed in</li>
  <li>Add the <code>UILabel</code> as a subview of the <code>UIImageView</code></li>
  </ol>
  
  <h2>Issues this might have</h2>
  
  <p>I can't approximate how quick this will be while scrolling, however this could be solved by drawing the text right into the <code>UIImage</code>, as it will be static. If the <code>UIImageView</code> holding the label would be put into a <code>UIScrollView</code>, would it be redrawn upon every scroll?</p>
  
  <p>Thank you a lot in advance!</p>