Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change color of NSString in drawAtPoint

I have this chunk of code here that draws a block with a one-character string on it:

CGContextDrawImage(context, CGRectMake([blok getLocation].x * xunit, [blok getLocation].y * yunit, 40, 40), [blok getImage].CGImage);
[[blok getSymbol] drawAtPoint:CGPointMake([blok getLocation].x * xunit+15, [blok getLocation].y * yunit) withFont:[UIFont fontWithName:@"Helvetica" size:24]];

It's working fine, but I've been doing some layout changes, and now I need it so that the string drawn will be white. Using the methods for setting the fill color and the stroke color haven't done anything. Is there some other way to do this?

like image 476
RaysonK Avatar asked Jul 31 '12 22:07

RaysonK


1 Answers

Set the foregroundcolor in the attributes and use the draw withAttributes functions

NSDictionary *attributes = [NSDictionary dictionaryWithObjects:
                            @[font, [UIColor whiteColor]]
                            forKeys:
                            @[NSFontAttributeName, NSForegroundColorAttributeName]];
[string drawInRect:frame withAttributes:attributes];
like image 71
Gapp Avatar answered Sep 25 '22 17:09

Gapp