text zeichnen mit Quartz 2D

Y

youssef

Neues Mitglied
Thread Starter
Dabei seit
27.08.2008
Beiträge
18
Reaktionspunkte
0
Hallo,

ich versuche seit 2 Stunden einen Text mit Quartz 2D zu zeichen aber ich kriege das nicht hin. ich habe sogar den code von quartz 2D programming Guide ausprobiert und auch ohne erfolg.
was mache ich da falsch?
Code:
- (void)drawRect:(CGRect)rect {
	// Drawing code
	
	CGContextRef context = UIGraphicsGetCurrentContext();
	
	// first draw background
	CGRect frame = self.frame;
	int w = frame.size.width;
	int h = frame.size.height;
	NSLog(@"w= %d",w);
	NSLog(@"h= %d",h);
	CGContextSetRGBFillColor(context, 0.85, 0.85, 0.85, 1.0); // Gray
	CGContextFillRect(context,frame);
	
	
	// Drawing with a black stroke color
	CGContextSetRGBStrokeColor(context, 0, 0, 1, 1);
	// And draw with a green color
	CGContextSetRGBFillColor(context, 0, 1, 0, .5);
	// Draw them with a 2.0 stroke width so they are a bit more visible.
	CGContextSetLineWidth(context, 2.0);
	
	CGAffineTransform myTextTransform;
	
	//drawing text
	myTextTransform = CGAffineTransformMakeRotation(50);
	CGContextSetTextMatrix(context,myTextTransform);
	CGContextSelectFont(context, "Times-Bold", h/10, kCGEncodingMacRoman); // set font and font size
	CGContextSetCharacterSpacing(context, 10);
	CGContextSetTextDrawingMode(context, kCGTextFillStroke); // set drawing mode. perform a fill operation on the text
	
	
	CGContextShowTextAtPoint(context, 40, 0, "test", 4); // draw the text
	
	
	/*for(int i=1; i<9; i++)
	{
		// Fill rect convenience equivalent to AddEllipseInRect(); FillPath();
		CGContextFillEllipseInRect(context, CGRectMake(w/8, i *(h/12), 20.0, 20.0));
		CGContextStrokeEllipseInRect(context, CGRectMake(w/8, i * (h/12), 20.0, 20.0));
		
		CGContextFillEllipseInRect(context, CGRectMake(6*w/8, i *(h/12), 20.0, 20.0));
		CGContextStrokeEllipseInRect(context, CGRectMake(6*w/8, i * (h/12), 20.0, 20.0));
		
		
	}*/
	
}
 
iPhone unterstützt kein Times-Bold

Hallo, ich habe das problem gelöst und poste meine Lösung falls jemand interessiert
kein Text wurde gezeichnet weil iPhone das Font Times-Bold nicht unterstützt.
ich habe ihn mit "Helvetica" ersetzt und dann ist ein Text auf den Bildschirm erschienen mit noch ein problem. der Text war gedreht.

mit:
Code:
 CGAffineTransform xform = CGAffineTransformMake(
            1.0,  0.0,
            0.0, -1.0,
            0.0,  0.0);
    CGContextSetTextMatrix(ctx, xform);
sieht der text wir gewünscht aus
 
Zurück
Oben Unten