之前走了很多弯路,包括自己定以emoji表情,自己创建view类去处理图文混排 ,当把这些焦头烂额的东西处理完了才发现 ,其实系统自带键盘是如此的方便,iOS 系统自带的表情在view,textfield,UIimageView展示时已经将uicode做过处理,直接展示成图片的形式,其实质依然是UTF8的 符号,如果你要自己定义图片,然后添加进textField 或者Label里,那你就中大奖了,图文混排 需要费很大的功夫处理。
//将数字转为
#define EMOJI_CODE_TO_SYMBOL(x) ((((0x808080F0 | (x & 0x3F000) >> 4) | (x & 0xFC0) << 10) | (x & 0x1C0000) << 18) | (x & 0x3F) << 24);
//获取默认表情数组
- (NSArray *)defaultEmoticons {
NSMutableArray *array = [NSMutableArray new];
for (int i=0x1F600; i<=0x1F64F; i++) {
if (i < 0x1F641 || i > 0x1F644) {
int sym = EMOJI_CODE_TO_SYMBOL(i);
NSString *emoT = [[NSString alloc] initWithBytes:&sym length:sizeof(sym)encoding:NSUTF8StringEncoding];
[array addObject:emoT];
}
}
return array;
}
//获取数组
NSArray *arrEmotion = [self defaultEmoticons];
//将表情放到UIButton里
CGFloat W = 30;
CGFloat H = 30;
CGFloat X;
CGFloat Y;
for (int i = 0; i count; i ++) {
X = 10 +(W+5) * (i%10);
Y = 260 + (i/10)* (H +5);
UIButton *biaoqing =[[UIButton alloc] init];
biaoqing.backgroundColor = [UIColor redColor];
biaoqing.frame = CGRectMake(X, Y, W, H);
[self.view addSubview:biaoqing];
NSString *Str = arrEmotion[i];
[biaoqing setTitle:Str forState:UIControlStateNormal];
biaoqing.tag = i;
[biaoqing addTarget:self action:@selector(biaoqingClick:)forControlEvents:UIControlEventTouchUpInside];
}
- (void) biaoqingClick:(UIButton *)biaoqing{
NSArray *emoji = [self defaultEmoticons];
NSString *str = emoji[biaoqing.tag];
self.textField.text = str;
}