ios将NSString与特殊字符转换为const char [英] ios convert NSString with special chars to const char

查看:780
本文介绍了ios将NSString与特殊字符转换为const char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图画一个字符串与CGContextShowTextAtPoint。
CGContextShowTextAtPoint只接受const char作为字符串输入。
我的问题是,一些字符串有特殊的字符,如ä,ö,ü等在其中。



如果我将这个字符串转换为一个

  NSString * label = @Küche 
const char * charLabel = [label UTF8String];

我得到一个奇怪的输出,其中ü用符号和方框替换...



该怎么办?

解决方案

c $ c> CGContextShowTextAtPoint 。
要绘制Unicode字符串,请使用 NSString UIKit添加 drawInRect:withFont:或(对于更多自定义绘图) CoreText framework 。 / p>

i m trying to draw a string with CGContextShowTextAtPoint. CGContextShowTextAtPoint only accepts "const char" as a string input. my problem is that some of the strings have special chars like ä,ö,ü etc in them.

if i convert this strings to a "const char"

NSString *label = @"Küche";
const char *charLabel = [label UTF8String];

i get a strange output, where the ü is replaced with signs and boxes...

what to do?

解决方案

You can draw only ASCII characters with CGContextShowTextAtPoint. To draw Unicode strings use either NSString UIKit Additions like drawInRect:withFont: or (for more customized drawing) CoreText framework.

这篇关于ios将NSString与特殊字符转换为const char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆