PDA

View Full Version : Help: Can't display text in graphics view




Zvi
Nov 3, 2008, 01:37 AM
Hi All,

I need ot display a string on the graph. Graph is built using quartz library. Initially I've tried to display text using quartz routines:

CGContextSelectFont (context,"Times-Bold",8,
kCGEncodingMacRoman);

CGContextSetCharacterSpacing (context, 10); // 4

CGContextSetTextDrawingMode (context, kCGTextFillStroke);
CGContextSetRGBFillColor (context, 1, 1, 1, 1); // 6

CGContextSetRGBStrokeColor (context, 1, 1, 1, 1); // 7

CGContextShowTextAtPoint(context, 55, 60,
"test", 4);


CGContextStrokePath(context);

I've pasted this code at the beginning of quartzdemo's linedrawing view code, no luck.
Later I've found on the net that iphone doesn't support a lot of fonts and looks like CGContextShowTextAtPoint has its own issues with internationalization.

So, eventually I've used this code for my drawView


-(void)drawView:(QuartzView*)view inContext:(CGContextRef)context bounds:(CGRect)bounds
{
NSString* myStr = @"Test";
UIFont* font = [UIFont systemFontOfSize:12.0];
[myStr drawInRect: CGRectMake(160, 240, 100, 130) withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];

}



Still nothing.

Any idea what am I doing wrong? It can't be that complicated to display a simple text...

Actually I've removed all quartz related code for now.


-(void)drawRect:(CGRect)rect
{

NSString* myStr = @"Test";
UIFont* font = [UIFont systemFontOfSize:12.0];
//[myStr drawInRect: CGRectMake(160, 240, 100, 130) withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter];
[myStr drawAtPoint:CGPointMake(160,240) forWidth:175 withFont:font minFontSize:10 actualFontSize:NULL lineBreakMode:UILineBreakModeWordWrap baselineAdjustment:UIBaselineAdjustmentNone];

}


neither drawinrect nor drawatpoint work... Font is initialized, but no text gets displayed.



PhoneyDeveloper
Nov 3, 2008, 10:02 AM
Maybe the text color isn't set?

There's some text drawing code in the 5th of the tableviewsuite examples in TimeZoneView.m

Zvi
Nov 3, 2008, 10:43 AM
Maybe the text color isn't set?

There's some text drawing code in the 5th of the tableviewsuite examples in TimeZoneView.m

Thanks :) That was it. UIColor wasn't set. That solved a problem with NSString drawing funcitons, but quartz text drawing still doesn't work.