2

I have code that does custom rendering inside of a drawRect method in a UIView subclass. I am trying to render text out using [NSString drawInRect] which works great, however it always shows up in white. After much googling and browsing SO I have no been able to find out how to change the color of a text. Any advice would be great.

Edit Below is the snippet of code inside my drawRect implementation

if(self.state != UIControlStateHighlighted)
{
    CGContextSaveGState(context);
    CGContextSetFillColorWithColor(context, color);
    CGContextSetShadowWithColor(context, CGSizeMake(0, 2), 3.0, shadowColor);
    CGContextAddPath(context, path);
    CGContextFillPath(context);
    [title drawInRect:rect withFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]];
    CGContextRestoreGState(context);
}
Seb
  • 3,414
  • 10
  • 73
  • 106

2 Answers2

7

Before drawing text, you have to set the color. Try this,

[[UIColor blackColor] set]; 
[title drawInRect:rect withFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]]; 
ronalchn
  • 12,225
  • 10
  • 51
  • 61
amfool
  • 71
  • 1
  • 2
3

Have you tried changing the current fill color?

[[UIColor redColor] setFill];
[string drawInRect:rect withFont:font];
Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
  • I've tried setting the fill and the stroke to various colors and still all I get is white text. – Seb Feb 29 '12 at 19:57