2015-10-13 65 views
1

我正在聊天應用程序中使用表情符號。從iOS中的UILabel的Unicode顯示錶情符號

當有人給我發送表情符號時,它看起來像這樣: - Hello...(worried) how are you(happy)?。這裏爲(worried)and (happy)指定了emojis的密鑰。

這是列表emojis和鍵和值。

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

@ChintaN謝謝..我已經檢查過這個鏈接,但這不是我所要求的。 –

回答

0

試試這個。它可能會幫助你。

添加一個標籤&寫viewDidLoad下面的代碼:

NSData *dataa = [valueUnicode dataUsingEncoding:NSUTF8StringEncoding]; 
NSString *valueEmoj = [[NSString alloc] initWithData:dataa encoding:NSNonLossyASCIIStringEncoding]; 

_lbl.text = valueEmoj; 
+0

我輸入valueUnicode = @「(酷)」,因爲它是在我的字典,但它顯示我(酷)標籤。 –

+0

你必須是unicode顯示錶情符號......看到這個鏈接http://punchdrunker.github.io/iOSEmoji/table_html/所有表情符號都有特定的unicode –

+0

我有我的個人表情符號,所以當我想將它轉換成unicode時NSString *的unicode = @ 「書呆子-48.gif」; NSData * dataa = [unicode dataUsingEncoding:NSUTF8StringEncoding]; NSString * valueEmoj = [[NSString alloc] initWithData:dataa encoding:NSNonLossyASCIIStringEncoding]; 它給我輸出就像它是字符串nerd-48.gif –

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; 

希望這會有所幫助。