Emoji的介绍参见wiki,iOS支持的emoji表情列表参见http://pukupi.com/post/1964/,iOS支持的emoji表情的Unicode编码范围为[0xE001,0xE05A]&[0xE101,0xE15A]&[0xE201,0xE253]&[0xE401&0xE44C]&[0xE501,0xE537],Unicode编码转为NSString的方法为[NSStringstringWithFormat:@"%C", i].使用如下代码可以弹出一个可以选择Emoji表情的输入框,
- (void)didSelectAFace:(id)sender{
UIButton*button = (UIButton*)sender;
NSString*emojiStr = [NSStringstringWithFormat:@"%C", button.tag];
textView.text= [NSStringstringWithFormat:@"%@%@",textView.text,emojiStr];
}
- (void)hideEmojiView{
[emojiViewremoveFromSuperview];
[emojiCloseButtonremoveFromSuperview];
}
- (void)showEmojiView{
CGFloatx = (self.view.frame.size.width-300.0f)/2;
CGFloaty =self.view.frame.size.height-190;
if(emojiView==nil) {
self.emojiView= [[UIViewalloc]initWithFrame:CGRectMake(x,y,300.0f,140.0f)];
emojiView.backgroundColor= [UIColorlightGrayColor];
emojiView.alpha=0.8;
emojiView.layer.cornerRadius=6;
[emojiView.layersetMasksToBounds:YES];
UIScrollView*emojiScrollView = [[UIScrollViewalloc]init];
emojiScrollView.frame=CGRectMake(0,0,300.0f,140.0f);
[emojiViewaddSubview:emojiScrollView];
intxIndex =0;
intyIndex =0;
intemojiRangeArray[10] = {0xE001,0xE05A,0xE101,0xE15A,0xE201,0xE253,0xE401,0xE44C,0xE501,0xE537};
for(intj =0; j<10; j+=2) {
intstartIndex = emojiRangeArray[j];
intendIndex = emojiRangeArray[j+1];
for(inti = startIndex ; i<= endIndex ; i++ ) {
UIButton*button = [UIButtonbuttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(6+ xIndex*32,6+ yIndex*32,32.0f,32.0f);
[buttonsetTitle:[NSStringstringWithFormat:@"%C", i]forState:UIControlStateNormal];
button.tag= i;
[buttonaddTarget:selfaction:@selector(didSelectAFace:)forControlEvents:UIControlEventTouchUpInside];
[emojiScrollViewaddSubview:button];
xIndex +=1;
if(xIndex ==9) {
xIndex =0;
yIndex +=1;
}
}
}
[emojiScrollViewsetContentSize:CGSizeMake(300.0f,12+ (yIndex+1)*32)];
//closeButton
self.emojiCloseButton= [UIButtonbuttonWithType:UIButtonTypeCustom];
emojiCloseButton.frame=CGRectMake(x-10.0f, y-10.0f,24.0f,24.0f);
[emojiCloseButtonsetImage:[UIImageimageNamed:@"dialog_close.png"]forState:UIControlStateNormal];
[emojiCloseButtonaddTarget:selfaction:@selector(hideEmojiView)forControlEvents:UIControlEventTouchUpInside];
}
else{
emojiView.frame=CGRectMake(x,y,300.0f,140.0f);
emojiCloseButton.frame=CGRectMake(x-10.0f, y-10.0f,24.0f,24.0f);
}
[self.viewaddSubview:emojiView];
[self.viewaddSubview:emojiCloseButton];
}
The complete list of iPhone emoji and their respective decimal character entities:
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |  |  |  |  |
 |  |  |
转载地址:http://pukupi.com/post/1964/