Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Zvi

macrumors newbie
Original poster
Sep 29, 2008
7
0
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:
Code:
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
Code:
-(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.

Code:
-(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

macrumors 68040
Sep 2, 2008
3,114
93
Maybe the text color isn't set?

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

Zvi

macrumors newbie
Original poster
Sep 29, 2008
7
0
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.