1
我遇到了一些問題,在圖像上繪製文本。當我試圖顯示英文文本時,一切正常。問題是,我需要本地化文本。當文字是俄語時,會顯示一些奇怪的符號。任何幫助,將不勝感激。CGContextShowTextAtPoint和西里爾文本
我用下面的代碼,以繪製文本:
CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 1);
char* text = (char *)[addText cStringUsingEncoding:NSUTF8StringEncoding];
CGContextSelectFont(context, "Impact", 20, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextShowTextAtPoint(context, 20, h+addHeightBelow, text, strlen(text));
它顯示以下內容:
所以結果,你應該使用的核心文本,並且代碼:
CTFontRef fontRef=CTFontCreateWithName((CFStringRef)@"Impact", 20.0f, NULL);
CGColorRef color=[UIColor blackColor].CGColor;
NSDictionary *attrDictionary=[NSDictionary dictionaryWithObjectsAndKeys:
(id)fontRef, (id)kCTFontAttributeName,
color, (id)kCTForegroundColorAttributeName,
nil];
NSAttributedString *stringToDraw=[[NSAttributedString alloc] initWithString:addText attributes:attrDictionary];
CTLineRef line=CTLineCreateWithAttributedString((CFAttributedStringRef)stringToDraw);
CGContextSetTextPosition(context, 20, h+addHeightBelow);
CTLineDraw(line, context);
CFRelease(line);
CFRelease(fontRef);
[stringToDraw release];
此問題的答案可能會有用。 http://stackoverflow.com/questions/6461980/how-to-display-international-accents-with-quartz-core-graphics-on-iphone – Yarlik