获取系统的emoji表情定制键盘
Posted Hakim_Fan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取系统的emoji表情定制键盘相关的知识,希望对你有一定的参考价值。
//将数字转为
#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;
}
以上是关于获取系统的emoji表情定制键盘的主要内容,如果未能解决你的问题,请参考以下文章