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

允我心安 提交于 2019-12-10 10:49:49

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/9996362/drawing-a-checkmark-nsstring-with-uikit-doesnt-respect-fill-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!