I'm putting text on top of various images and came across this article on overlaying text on images which suggests putting blurry dark rectangle around the bounds of the text to help it stand out from the image. Basically, as if the shadow of the text were a rectangle. They call it a scrim.
I tried this first by really blurring the shadow but with thin text it really isn't visible. I figure I need to somehow draw a blurry/shadowy rectangle behind the text. I figure there's some way to draw this with CoreGraphics/CoreText. I'm not very experienced in drawing wit either of these as I've dealt mostly with OpenGL.
Any suggestion for trying to create a blurry rectangular shadow when drawing NSAttributedStrings? Could I somehow make the shadow come from another object like a rectangle without drawing that object.
There’s a pretty easy way to do this with the CALayer shadowPath property. Normal usage looks like this:
myLabel.layer.shadowPath = [UIBezierPath bezierPathWithRect:myLabel.layer.bounds].CGPath;
myLabel.layer.shadowRadius = 10;
myLabel.layer.shadowOpacity = 0.5;
In your case, it sounds like you want a larger box around your label, so you’ll want to change the rectangle being passed into +bezierPathWithRect:
. That path is specified in the layer’s coordinate space (i.e. the top-left is 0,0), so if you want a box that starts 50pt to the left of the label and 30pt above, and is 200x100pt in size, you’d do this instead:
myLabel.layer.shadowPath = [UIBezierPath bezierPathWithRect:CGRectMake(-50, -30, 200, 100)].CGPath;
…then play with the shadowRadius
and shadowOpacity
properties to suit your taste.