Search code examples
iosnsstringuikitdrawinguicolor

Drawing a checkmark NSString with UIKit doesn't respect fill color


I'm trying to draw a checkmark in green with UIKit, but it is drawn in black instead. Here is the code:

[[UIColor greenColor] set];
[@"✔" drawAtPoint:CGPointZero withFont:[UIFont systemFontOfSize:[UIFont systemFontSize]]];

Other strings are properly drawn in green with this method. I suspect that the checkmark glyph contains color information that overrides my choice of fill color, but drawing the same glyph with color in an UIWebView works.

Is there a way to get the checkmark drawn in green anyway?


Solution

  • I suspect that the checkmark glyph in question might not be available in the system font, and the text system is doing its best to fulfill your request using a different font (it's probably coming from ZapfDingbatsITC). In the process, perhaps, the color is getting stripped.

    One thing you might try is turning that glyph into a bezier path, then filling that with the desired color.