iOS系统自带的表情在view,textfield,UIimageView展示时已经将uicode做过处理,直接展示成图片的形式,其实质依然是UTF8的符号.想要获取系统的表情,要首先知道表情对应的UTF8 的编码方式,我将其中一部分的图片展示出来 ,然后用UIButton排列,iOS 7后又增加了300多个表情符号,这些都可以百度查到,现在上代码:
//将数字转为
#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(inti=0x1F600;i<=0x1F64F;i++) {
if(i < 0x1F641|| i > 0x1F644){
intsym = EMOJI_CODE_TO_SYMBOL(i);
NSString*emoT= [[NSStringalloc]initWithBytes:&symlength:sizeof(sym)encoding:NSUTF8StringEncoding];
[arrayaddObject:emoT];
}
}
returnarray;
}
//获取数组
NSArray*arrEmotion = [selfdefaultEmoticons];
//将表情放到UIButton里
CGFloatW = 30;
CGFloatH = 30;
CGFloatX;
CGFloatY;
for(inti = 0;i count; i ++) {
X = 10+(W+5)* (i%10);
Y = 260+ (i/10)*(H +5);
UIButton*biaoqing =[[UIButtonalloc]init];
biaoqing.backgroundColor= [UIColorredColor];
biaoqing.frame= CGRectMake(X,Y, W, H);
[self.viewaddSubview:biaoqing];
NSString*Str = arrEmotion[i];
[biaoqing setTitle:StrforState:UIControlStateNormal];
biaoqing.tag= i;
[biaoqing addTarget:selfaction:@selector(biaoqingClick:)forControlEvents:UIControlEventTouchUpInside];
}
- (void)biaoqingClick:(UIButton*)biaoqing{
NSArray*emoji = [selfdefaultEmoticons];
NSString*str = emoji[biaoqing.tag];
self.textField.text= str;
}