2011-07-14 42 views
0

使用CGContextSelectFont繪製到位圖,但使用某種編碼。使用其他語言時,這不起作用。基於當前語言選擇編碼的推薦方法是什麼?請注意,本地化工作正常。如何使用CGContextSelectFont選擇基於當前語言的編碼?

CGContextDrawImage(context, rect, image.CGImage); 

NSString *temp = [[NSString alloc] initWithFormat:@"%@%@",[Localization string:@"WaitingForDownloadFor"],title]; 
const char *text = [temp UTF8String]; 
CGContextSelectFont(context, "Arial", 18, kCGEncodingMacRoman); //*** line in question 
CGContextSetTextDrawingMode(context, kCGTextFill); 
CGContextSetRGBFillColor(context, 1, 1, 1, 1); 
CGContextShowTextAtPoint(context, 10, h/2, text, strlen(text)); 
+0

通常,Mac OS X和iOS中的所有字符串都是UTF-8。看到[這個問題](http://stackoverflow.com/questions/275437/unicode-character-not-showing)。 – 2011-07-14 14:27:44

+0

這是真正回答上面的代碼.... – ort11

回答

0

下面是回答問題的代碼,感謝指針....本地化類是一個自定義類。

NSString *temp = [[NSString alloc] initWithFormat:@"%@%@",[Localization string:@"Downloading"],title]; 
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst); 
CGContextDrawImage(context, rect, image.CGImage);  
UIGraphicsPushContext(context); 
CGContextSetRGBFillColor(context, 1, 1, 1, 1); 
UIFont* font = [UIFont fontWithName:@"Arial" size:18.0]; 
// need to do this or Mirrored Backwards 
CGContextTranslateCTM(context, 0, h); 
CGContextScaleCTM(context, 1.0, -1.0); 
[temp drawAtPoint:CGPointMake(10.0,h/2) withFont:font]; 
CGImageRef imageRef = CGBitmapContextCreateImage(context); 
UIImage *image2 = [[UIImage imageWithCGImage:imageRef] retain]; 
CGContextRelease(context); 
CGColorSpaceRelease(colorSpace);  
UIGraphicsPopContext();