I'm trying to subclass (because thats probably the easiest way to do it) UILabel so it's text 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.

Parameters to pass the subclass
- Background image
- 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.
Logic while drawing the label
- Create a mask with the text - the content of the mask would only be the text itself, not the background.
- Crop out the specific part (rect) of the Background image which is overlaid by the label.
- 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.
- Invert the image's colors (with this method probably) or use
kCGBlendModeDifferencein some way perhaps? - Draw all that in one of the methods UILabel's
drawRectordrawTextInRectmethods.
Usage
The usage of this would probably be something like
- Alloc an
UIImage - Display it in an
UIImageView - Create the
UILabelsubclass with the inverted text color relative to the part of the image theUILabelwill be placed in - Add the
UILabelas a subview of theUIImageView
Issues this might have
I can't approximate how quick this will be while scrolling, however this could be solved by drawing the text right into the UIImage, as it will be static. If the UIImageView holding the label would be put into a UIScrollView, would it be redrawn upon every scroll?
Thank you a lot in advance!