- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 CGContextShowTextAtPoint 调用在我的 View 上打印 ° 或 µ。代码行如图所示。
int number = 100;
NSString *theText2 = [NSString stringWithFormat:@"%d°", number];
CGContextShowTextAtPoint(context, 10, 5, [theText2 cStringUsingEncoding:NSUTF8StringEncoding], [theText2 length]);
输出结果为
“100¬”
如果我增加打印的字符串的长度,它会显示以下内容
“100°”
预期的输出应该是:
“100°”
这肯定与打印 unicode 字符有关。
最佳答案
对于 CGContextShowTextAtPoint
,您必须将字符串转换为在 CGContextSelectFont
中指定的编码。这很可能是“Mac Roman”编码。 CGContextShowTextAtPoint
的最后一个参数是转换后的字符串的长度,而不是NSString
的长度:
CGContextSelectFont(context, "Helvetica", 10.0, kCGEncodingMacRoman);
int number = 100;
NSString *theText2 = [NSString stringWithFormat:@"%d°µ", number];
const char *s = [theText2 cStringUsingEncoding:NSMacOSRomanStringEncoding];
CGContextShowTextAtPoint(context, 10, 5, s, strlen(s));
请注意,这仅在您使用“Mac Roman”字符集中的字符时有效。(由于 Mac Roman 编码的一些历史变化,它也不适用于欧元字符。)
对于一般的 Unicode 字符串,NSString
方法 drawAtPoint:withFont:
可能更适合。
关于objective-c - 使用 CGContextShowTextAtPoint 打印时,在 ° 符号之前使用 ¬ 打印 unicode 符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13738158/
我正在开发一个应用程序,我使用CGContextShowTextAtPoint在屏幕上显示文本。我还想显示日语字符,但 CGContextShowTextAtPoint 接受 C 字符串作为输入。那么
我有一些相当简单的代码,将一些文本绘制到 CGContext 中。这是摘录(略有编辑)。 CGContextSelectFont(context, "Helvetica", 1.5, kCGE
我正在使用以下内容在 iOS 中的 PDF 上绘制文本: CGContextSelectFont (pdfContext, "Helvetica Bold", 14, kCGEncodingMacRo
我正在使用以下代码在我的自定义 View 中绘制一些文本: - (void)drawProgramDescription:(CGContextRef) context { UIGraphics
为什么下面的代码忽略了空白? UIColor *textColor = [UIColor colorWithRed:153.0/255.0 green:102.0/255.0 blue:51.0/25
我试图通过Quartz通过CGContextShowTextAtPoint()将一些文本绘制到NSView上。这工作得很好,直到我覆盖 (BOOL)isFlipped 以在我的 NSView 子类中返
我在图像上绘制文本时遇到一点问题。当我尝试显示英文文本时,一切正常。问题是,我需要本地化文本。当文本为俄语时,会显示一些奇怪的符号。任何帮助将不胜感激。 我正在使用以下代码来绘制文本: CGConte
我正在使用以下方式在图像上书写: float shadowColorValues[] = {0, 0, 0, .3}; CGContextSetShadowWithColor(context, CGS
以下内容将被视为在 iOS 7 中已弃用:CG上下文选择字体,CGContextShowTextAtPoint。我应该改用什么? 最佳答案 您可以使用[yourString drawAtPoint:a
- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGCon
由于 CGContextShowTextAtPoint 在 iOS 7 中已弃用,我想将 CGContextShowTextAtPoint 更改为 drawAtPoint 但文本正在输出。 //Ad
CGContextSelectFont 和 CGContextShowTextAtPoint 在 iOS 7 中已被弃用。 C 中的等价物是什么? 我看到的所有答案都给出了 Objective-C 的
我正在使用 CGContextShowTextAtPoint 绘制一个字符串。因此,我需要将我想绘制的 NSString 转换为 c 字符串。不幸的是,欧元货币符号等特殊符号未正确显示。 CGCont
我正在使用 CGContextShowTextAtPoint 调用在我的 View 上打印 ° 或 µ。代码行如图所示。 int number = 100; NSString *theText2 =
我是一名优秀的程序员,十分优秀!