Ios 使用unicode代码显示字符
我使用自定义字体来显示图标。每个图标都是一个字符 我可以通过如下方式复制/粘贴字符在uicontrol中使用它们:Ios 使用unicode代码显示字符,ios,objective-c,Ios,Objective C,我使用自定义字体来显示图标。每个图标都是一个字符 我可以通过如下方式复制/粘贴字符在uicontrol中使用它们: myLabel.text = @""; 或使用unicode十六进制代码: myLabel.text = [NSString stringWithUTF8String:"\uf000"]; 或 现在,我正尝试使用字典中存储为NSString的十六进制字符代码使其更具动态性: NSString *glassIcon = [charactersList objectForKey:
myLabel.text = @"";
或使用unicode十六进制代码:
myLabel.text = [NSString stringWithUTF8String:"\uf000"];
或
现在,我正尝试使用字典中存储为NSString的十六进制字符代码使其更具动态性:
NSString *glassIcon = [charactersList objectForKey:@"icon-glass"]; //glassIcon = f000
但我无法在标签中显示此字符
我试过了
myLabel.text = [NSString stringWithFormat:@"%s", [subString UTF8String]];
或
但这些都不管用
我确信我遗漏了一些明显的东西,但我找不到。试试这个:
/* Convert it to an integer. */
uint16_t code = (uint16_t)strtol(glassIcon.UTF8String, NULL, 16);
/* Convert the charcode to a string */
myLabel.text = [NSString stringWithFormat:@"%c%c", (char)((code >> 8) & 0xff), (char)(code & 0xff)];
您可能需要将其放在文件的顶部,但不确定:
#include <string.h>
#包括
/* Convert it to an integer. */
uint16_t code = (uint16_t)strtol(glassIcon.UTF8String, NULL, 16);
/* Convert the charcode to a string */
myLabel.text = [NSString stringWithFormat:@"%c%c", (char)((code >> 8) & 0xff), (char)(code & 0xff)];
#include <string.h>