首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将Unicode笑脸转换为nsstring ios

将Unicode笑脸转换为nsstring ios
EN

Stack Overflow用户
提问于 2014-05-02 11:08:13
回答 1查看 742关注 0票数 0

我在做聊天应用,我想加入笑脸的支持。我可以在iOS中使用像\ue415这样的unicode直接显示笑脸:-)。当我使用此unicode字符串发送消息时,它比其他方接收的是方框,比如。如何将unicode字符转换为nsstring。

我在收集视图中使用情感,就像下面

代码:

代码语言:javascript
复制
data = [NSArray arrayWithObjects:@"\ue415",@"\ue056",@"\ue057",@"\ue414",@"\ue405",@"\ue106",@"\ue418",@"\ue417",@"\ue40d",@"\ue40a",@"\ue404",@"\ue105",@"\ue409",@"\ue40e",@"\ue402",@"\ue108",@"\ue403",@"\ue058",@"\ue407",@"\ue401",@"\ue40f",@"\ue40b",@"\ue406",@"\ue413",@"\ue411",@"\ue412",@"\ue410",@"\ue107",@"\ue059",@"\ue416",@"\ue408",@"\ue40c",@"\ue11a",@"\ue10c",@"\ue32c",@"\ue32a",@"\ue32d",@"\ue328",@"\ue32b",@"\ue022",@"\ue023",nil];

CollectionView代表方法

代码语言:javascript
复制
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *CellIdentifier = @"EmojiCell";

    UICollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    cell.backgroundColor = [UIColor grayColor];

    UILabel *lable = (UILabel *)[cell viewWithTag:100];

    lable.text = [data objectAtIndex:indexPath.row];

    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

    messageField.text = [NSString stringWithFormat:@"%@%@",messageField.text,[data objectAtIndex:indexPath.row]];
}

发送消息的代码

代码语言:javascript
复制
NSString *messageStr = self.messageField.text ;

    if([messageStr length] > 0) {

        NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
        [body setStringValue: messageStr];

        XMPPJID *jid = [XMPPJID jidWithString:chatWithUser];

        NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
        [message addAttributeWithName:@"type" stringValue:@"chat"];
        [message addAttributeWithName:@"to" stringValue:[jid full]];
        [message addChild:body];

        [self.xmppStream sendElement:message];
    }
EN

回答 1

Stack Overflow用户

发布于 2014-05-02 11:15:43

只要改变symbolCode。

代码语言:javascript
复制
unichar symbolCode = 0xf086;
NSString *chatIcon =[NSString stringWithCharacters:&symbolCode length:1];

为您编辑:

代码语言:javascript
复制
unichar symbolCode = 0xE415;
NSString *smile =[NSString stringWithCharacters:&symbolCode length:1];
NSLog(@"%@",smile);
UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 100, 50)];
lab.text = smile;
[self.view addSubview:lab];

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23426686

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档