emoji的长度问题
不同的emoji的长度是不同的
随机打印几个emoji长度:
NSString *emoji_1 = @"✋"; //长度:1
NSString *emoji_2 = @"✋🏻"; //长度:3
NSString *emoji_3 = @"😘"; //长度:2
今天遇到的问题
NSString *text = @"✋🏻Hi!~ Xiaoming";
NSMutableAttributedString *attriStr = [[NSMutableAttributedString alloc] initWithString:text];
[attriStr addAttribute:NSFontAttributeName value:[QMFont systemFontOfSize:36] range:NSMakeRange(0, 1)];
nameLable.attributedText = attriStr;
图片.png
应该改为:
NSString *name = @"Hi!~ Xiaoming";
NSString *text = [@"✋🏻" stringByAppendingString:name];
NSRange r = [text rangeOfString:name];
NSMutableAttributedString *attriStr = [[NSMutableAttributedString alloc] initWithString:text];
[attriStr addAttribute:NSFontAttributeName value:[QMFont systemFontOfSize:36] range:NSMakeRange(0, r.location)];
nameLable.attributedText = attriStr;
图片.png
网友评论