Help: Can't display text in graphics view

Discussion in 'iPhone/iPad Programming' started by Zvi, Nov 2, 2008.

  1. Zvi
    macrumors newbie

    Joined:
    Sep 29, 2008
    #1
    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.
     
  2. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    Maybe the text color isn't set?

    There's some text drawing code in the 5th of the tableviewsuite examples in TimeZoneView.m
     
  3. Zvi
    thread starter macrumors newbie

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

Share This Page