Iphone 如何在Objective-C中的PDF中添加欧元货币符号
我正在用Objective-C制作一个PDF文件,一切进展顺利。但当我在PDF中添加一些curreny符号时,它显示了完全不同的东西 将2060,0欧元改为2060,0欧元 我已使用以下代码在PDF中绘制文本:Iphone 如何在Objective-C中的PDF中添加欧元货币符号,iphone,objective-c,unicode,pdf-generation,Iphone,Objective C,Unicode,Pdf Generation,我正在用Objective-C制作一个PDF文件,一切进展顺利。但当我在PDF中添加一些curreny符号时,它显示了完全不同的东西 将2060,0欧元改为2060,0欧元 我已使用以下代码在PDF中绘制文本: NSString *reducedString = @"€4,854,525"; CGContextShowTextAtPoint (currentContext,xPos, yPos, [textToDraw UTF8String], [reducedString length]);
NSString *reducedString = @"€4,854,525";
CGContextShowTextAtPoint (currentContext,xPos, yPos, [textToDraw UTF8String], [reducedString length]);
有人知道如何用同样的代码画欧元符号吗?文本编码中有什么我需要更改的吗
[reducedString drawAtPoint:CGPointMake(xPos ,yPos) withFont:[UIFont systemFontOfSize:15];
提前感谢。尝试使用欧元符号的unicode
\u20AC
试试这个
//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字符串。无需转换为常量字符。正确的方法是需要使用NSNumberFormatter
NSInteger currency = 4345;
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSString *result = [numberFormatter stringFromNumber:[NSNumber numberWithInteger:currency]];
结果将是带有货币符号的字符串,具体取决于区域设置。drawAtPoint有什么问题?因为这样可以正确处理编码。