1
由於某些原因,當我嘗試在我的iPhone應用程序中將貨幣符號打印到PDF文檔中時,我得到的是印刷而不是£。 (當iPhone設置爲英國設置時,使用英鎊符號)。UTF8String產生字面磅符號¬£objective-c
這是我的代碼:
text = [NSString stringWithFormat:@"%@", [Helper convertDoubleToCurrencyString:[item.Total floatValue]]];
WriteOutTextInPDF(pdfContext, [text UTF8String], priceX, currentY, 16);
+(NSString*) convertDoubleToCurrencyString:(double) d{
NSDecimalNumber *decimal = (NSDecimalNumber*)[NSDecimalNumber numberWithDouble:d];
NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
return [currencyFormatter stringFromNumber:decimal];
}
void WriteOutTextInPDF(CGContextRef pdfContext, const char *text, int x, int y, int fontSize){
CGContextSelectFont (pdfContext, "Helvetica", fontSize, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (pdfContext, kCGTextFill);
CGContextSetRGBFillColor (pdfContext, 0, 0, 0, 1);
CGContextShowTextAtPoint (pdfContext, x, y, text, strlen(text));
}
任何想法如何,我得到了符號,不要使用這種表示?
任何幫助將不勝感激。
謝謝。這解釋了這一點。我注意到這兩個字節,但不知道寫出它們的Mac羅馬錶示。 – user646598 2011-03-06 08:45:12