2012-11-23 43 views
3

我正在Objective-C中生成PDF文件,并且一切顺利。但是当我在PDF中添加一些curreny符号时,它显示了完全不同的东西。如何在PDF中添加欧元货币符号Objective-C

,C†2,060,0而不是€2,060,0

我使用下面的代码的PDF绘制文本:

NSString *reducedString = @"€4,854,525"; 
CGContextShowTextAtPoint (currentContext,xPos, yPos, [textToDraw UTF8String], [reducedString length]); 

任何人都知道如何绘制的欧元符号使用相同的代码?有什么我需要改变文本编码?

[reducedString drawAtPoint:CGPointMake(xPos ,yPos) withFont:[UIFont systemFontOfSize:15]; 

在此先感谢。

+0

'drawAtPoint'有什么问题?因为那应该正确处理编码。 –

回答

6

尝试使用欧元符号的Unicode

\u20AC 
0

试试这个

//for the document Header 
NSString *textToDraw = @"Your text"; 
UIFont *font = [UIFont boldSystemFontOfSize:18.0]; 
CGSize stringSize = [textToDraw sizeWithFont:font constrainedToSize:CGSizeMake(pageSize.width - 2*kBorderInset, pageSize.height - 2*kBorderInset - 2*kMarginInset) lineBreakMode:UILineBreakModeWordWrap]; 
//for title 
fYheight=fYheight+25; 
CGRect renderingRect = CGRectMake(kBorderInset, fYheight, pageSize.width - 2*kBorderInset, stringSize.height); 
[textToDraw drawInRect:renderingRect withFont:font lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentCenter]; 

您的文本添加到字符串textToDraw。无需转换为常量字符。

1

正确的做法是需要使用NSNumberFormatter。

NSInteger currency = 4345; 
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease]; 
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; 
NSString *result = [numberFormatter stringFromNumber:[NSNumber numberWithInteger:currency]]; 

而且结果将是货币符号取决于语言环境的字符串。