我正在聊天应用中使用表情符号。
当有人在信息中发送表情符号时,它看起来像这样: - Hello...(worried) how are you(happy)?
。这里为(worried)and (happy)
分配了表情符号的键。
这是表情符号和键和值的列表。
dictemoji = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"worried-48.gif",@"(worried)",
@"sad-48.gif",@"(sad)",
@"bandit48.gif",@"(bandit)",
@"wink48.gif",@"(wink)",
@"surprised48.gif",@"(surprised)",
@"smirking48.gif",@"(smirking)",
@"laugh48.gif",@"(laugh)",
@"cool48.gif",@"(cool)",
@"stoned-48.gif",@"(stoned)",
@"smile-48.gif",@"(smile)",
@"nerd-48.gif",@"(nerd)",
@"happy-48.gif",@"(happy)",
@"evil-grin-48.gif",@"(evil-grin)",
@"tongue48.gif",@"(tongue)",
@"lips-sealed-48.gif",@"(lips-sealed)",
@"GIF48.gif",@"(GIF)",
@"dull48.gif",@"(dull)",
nil];
当我收到消息Hello...(worried) how are you(happy)?
时,我想在标签中看到我的表情符号,而不是(担心)和(快乐)。
那我怎么能用表情符号而不是那些词呢?
修改: - 当有人向我发送带有短信的表情符号时,它将替换为字典值:
for (NSString *emojiKey in dictemoji.allKeys)
{
if ([message containsString:emojiKey])
{
message = [message stringByReplacingOccurrencesOfString:emojiKey withString:[dictemoji valueForKey:emojiKey]];
}
}
// helllo(sad)...how are you(smile)...? ----->it will look like helllo(sad-48.gif)...how are you(smile-48.gif)...?
NSLog(@"message updated:%@",message);
cell.textLabel.text=message;
所以,我想在标签上打印(sad-48.gif)和(smile-48.gif)的表情符号。
答案 0 :(得分:0)
试试这个。它可能对你有帮助。
添加一个标签&在viewDidLoad
中编写以下代码:
NSData *dataa = [valueUnicode dataUsingEncoding:NSUTF8StringEncoding];
NSString *valueEmoj = [[NSString alloc] initWithData:dataa encoding:NSNonLossyASCIIStringEncoding];
_lbl.text = valueEmoj;
答案 1 :(得分:0)
你必须这样使用;
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [UIImage imageNamed:[dictemoji valueForKey:emojiKey]];
NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
NSMutableAttributedString *myString= [[NSMutableAttributedString alloc] initWithString:@"My label text"];
[myString appendAttributedString:attachmentString];
cell.attributedText = myString;
希望这会有所帮助。