iOS应用中增加emoji表情输入功能

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 = [NSString stringWithFormat:@"%C", button.tag];

textView.text = [NSString stringWithFormat:@"%@%@",textView.text,emojiStr];

}

 

- (void)hideEmojiView{

 

[emojiView removeFromSuperview];

 

[emojiCloseButton removeFromSuperview];

}

 

- (void)showEmojiView{

 

CGFloat x = (self.view.frame.size.width-300.0f)/2;

CGFloat y = self.view.frame.size.height - 190;

 

if (emojiView == nil) {

 

self.emojiView = [[UIView allocinitWithFrame:CGRectMake(x,y, 300.0f140.0f)];

emojiView.backgroundColor = [UIColor lightGrayColor];

emojiView.alpha = 0.8;

emojiView.layer.cornerRadius = 6;

[emojiView.layer setMasksToBounds:YES];

 

UIScrollView *emojiScrollView = [[UIScrollView allocinit];

emojiScrollView.frame = CGRectMake(00 ,300.0f140.0f);

[emojiView addSubview:emojiScrollView];

 

int xIndex = 0;

int yIndex = 0;

 

int emojiRangeArray[10] = {0xE001,0xE05A,0xE101,0xE15A,0xE201,0xE253,0xE401,0xE44C,0xE501,0xE537};

 

for (int j = 0 ; j<10 ; j+=2 ) {

 

int startIndex = emojiRangeArray[j];

int endIndex = emojiRangeArray[j+1];

 

for (int i = startIndex ; i<= endIndex ; i++ ) {

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

button.frame = CGRectMake(6 + xIndex*326 + yIndex*3232.0f32.0f);

[button setTitle:[NSString stringWithFormat:@"%C", i]forState:UIControlStateNormal];

button.tag = i;

[button addTarget:self action:@selector(didSelectAFace:)forControlEvents:UIControlEventTouchUpInside];

[emojiScrollView addSubview:button];

 

xIndex += 1;

if (xIndex == 9) {

xIndex = 0;

yIndex += 1;

}

}

}

 

[emojiScrollView setContentSize:CGSizeMake(300.0f12 + (yIndex+1)*32)];

 

//closeButton

self.emojiCloseButton = [UIButton buttonWithType:UIButtonTypeCustom];

emojiCloseButton.frame = CGRectMake(x-10.0f , y-10.0f , 24.0f24.0f);

[emojiCloseButton setImage:[UIImage imageNamed:@"dialog_close.png"]forState:UIControlStateNormal];

[emojiCloseButton addTarget:self action:@selector(hideEmojiView)forControlEvents:UIControlEventTouchUpInside];

 

}

else {

emojiView.frame = CGRectMake(x,y, 300.0f140.0f);

emojiCloseButton.frame = CGRectMake(x-10.0f , y-10.0f , 24.0f24.0f);

}

 

[self.view addSubview:emojiView];

[self.view addSubview:emojiCloseButton];

 

}

 

iPhone Emoji Decimal Character Entities

The complete list of iPhone emoji and their respective decimal character entities:

&#xe415; &#xe056; &#xe057; &#xe414; &#xe405; &#xe106; &#xe418;
&#xe417; &#xe40d; &#xe40a; &#xe404; &#xe105; &#xe409; &#xe40e;
&#xe402; &#xe108; &#xe403; &#xe058; &#xe407; &#xe401; &#xe40f;
&#xe40b; &#xe406; &#xe413; &#xe411; &#xe412; &#xe410; &#xe107;
&#xe059; &#xe416; &#xe408; &#xe40c; &#xe11a; &#xe10c; &#xe32c;
&#xe32a; &#xe32d; &#xe328; &#xe32b; &#xe022; &#xe023; &#xe327;
&#xe329; &#xe32e; &#xe32f; &#xe335; &#xe334; &#xe021; &#xe337;
&#xe020; &#xe336; &#xe13c; &#xe330; &#xe331; &#xe326; &#xe03e;
&#xe11d; &#xe05a; &#xe00e; &#xe421; &#xe420; &#xe00d; &#xe010;
&#xe011; &#xe41e; &#xe012; &#xe422; &#xe22e; &#xe22f; &#xe231;
&#xe230; &#xe427; &#xe41d; &#xe00f; &#xe41f; &#xe14c; &#xe201;
&#xe115; &#xe428; &#xe51f; &#xe429; &#xe424; &#xe423; &#xe253;
&#xe426; &#xe111; &#xe425; &#xe31e; &#xe31f; &#xe31d; &#xe001;
&#xe002; &#xe005; &#xe004; &#xe51a; &#xe519; &#xe518; &#xe515;
&#xe516; &#xe517; &#xe51b; &#xe152; &#xe04e; &#xe51c; &#xe51e;
&#xe11c; &#xe536; &#xe003; &#xe41c; &#xe41b; &#xe419; &#xe41a;
&#xe04a; &#xe04b; &#xe049; &#xe048; &#xe04c; &#xe13d; &#xe443;
&#xe43e; &#xe04f; &#xe052; &#xe053; &#xe524; &#xe52c; &#xe52a;
&#xe531; &#xe050; &#xe527; &#xe051; &#xe10b; &#xe52b; &#xe52f;
&#xe528; &#xe01a; &#xe134; &#xe530; &#xe529; &#xe526; &#xe52d;
&#xe521; &#xe523; &#xe52e; &#xe055; &#xe525; &#xe10a; &#xe109;
&#xe522; &#xe019; &#xe054; &#xe520; &#xe306; &#xe030; &#xe304;
&#xe110; &#xe032; &#xe305; &#xe303; &#xe118; &#xe447; &#xe119;
&#xe307; &#xe308; &#xe444; &#xe441;      
&#xe436; &#xe437; &#xe438; &#xe43a; &#xe439; &#xe43b; &#xe117;
&#xe440; &#xe442; &#xe446; &#xe445; &#xe11b; &#xe448; &#xe033;
&#xe112; &#xe325; &#xe312; &#xe310; &#xe126; &#xe127; &#xe008;
&#xe03d; &#xe00c; &#xe12a; &#xe00a; &#xe00b; &#xe009; &#xe316;
&#xe129; &#xe141; &#xe142; &#xe317; &#xe128; &#xe14b; &#xe211;
&#xe114; &#xe145; &#xe144; &#xe03f; &#xe313; &#xe116; &#xe10f;
&#xe104; &#xe103; &#xe101; &#xe102; &#xe13f; &#xe140; &#xe11f;
&#xe12f; &#xe031; &#xe30e; &#xe311; &#xe113; &#xe30f; &#xe13b;
&#xe42b; &#xe42a; &#xe018; &#xe016; &#xe015; &#xe014; &#xe42c;
&#xe42d; &#xe017; &#xe013; &#xe20e; &#xe20c; &#xe20f; &#xe20d;
&#xe131; &#xe12b; &#xe130; &#xe12d; &#xe324; &#xe301; &#xe148;
&#xe502; &#xe03c; &#xe30a; &#xe042; &#xe040; &#xe041; &#xe12c;
&#xe007; &#xe31a; &#xe13e; &#xe31b; &#xe006; &#xe302; &#xe319;
&#xe321; &#xe322; &#xe314; &#xe503; &#xe10e; &#xe318; &#xe43c;
&#xe11e; &#xe323; &#xe31c; &#xe034; &#xe035; &#xe045; &#xe338;
&#xe047; &#xe30c; &#xe044; &#xe30b; &#xe043; &#xe120; &#xe33b;
&#xe33f; &#xe341; &#xe34c; &#xe344; &#xe342; &#xe33d; &#xe33e;
&#xe340; &#xe34d; &#xe339; &#xe147; &#xe343; &#xe33c; &#xe33a;
&#xe43f; &#xe34b; &#xe046; &#xe345; &#xe346; &#xe348; &#xe347;
&#xe34a; &#xe349;          
&#xe036; &#xe157; &#xe038; &#xe153; &#xe155; &#xe14d; &#xe156;
&#xe501; &#xe158; &#xe43d; &#xe037; &#xe504; &#xe44a; &#xe146;
&#xe50a; &#xe505; &#xe506; &#xe122; &#xe508; &#xe509; &#xe03b;
&#xe04d; &#xe449; &#xe44b; &#xe51d; &#xe44c; &#xe124; &#xe121;
&#xe433; &#xe202; &#xe135; &#xe01c; &#xe01d; &#xe10d; &#xe136;
&#xe42e; &#xe01b; &#xe15a; &#xe159; &#xe432; &#xe430; &#xe431;
&#xe42f; &#xe01e; &#xe039; &#xe435; &#xe01f; &#xe125; &#xe03a;
&#xe14e; &#xe252; &#xe137; &#xe209; &#xe154; &#xe133; &#xe150;
&#xe320; &#xe123; &#xe132; &#xe143; &#xe50b; &#xe514; &#xe513;
&#xe50c; &#xe50d; &#xe511; &#xe50f; &#xe512; &#xe510; &#xe50e;
&#xe21c; &#xe21d; &#xe21e; &#xe21f; &#xe220; &#xe221; &#xe222;
&#xe223; &#xe224; &#xe225; &#xe210; &#xe232; &#xe233; &#xe235;
&#xe234; &#xe236; &#xe237; &#xe238; &#xe239; &#xe23b; &#xe23a;
&#xe23d; &#xe23c; &#xe24d; &#xe212; &#xe24c; &#xe213; &#xe214;
&#xe507; &#xe203; &#xe20b; &#xe22a; &#xe22b; &#xe226; &#xe227;
&#xe22c; &#xe22d; &#xe215; &#xe216; &#xe217; &#xe218; &#xe228;
&#xe151; &#xe138; &#xe139; &#xe13a; &#xe208; &#xe14f; &#xe20a;
&#xe434; &#xe309; &#xe315; &#xe30d; &#xe207; &#xe229; &#xe206;
&#xe205; &#xe204; &#xe12e; &#xe250; &#xe251; &#xe14a; &#xe149;
&#xe23f; &#xe240; &#xe241; &#xe242; &#xe243; &#xe244; &#xe245;
&#xe246; &#xe247; &#xe248; &#xe249; &#xe24a; &#xe24b; &#xe23e;
&#xe532; &#xe533; &#xe534; &#xe535; &#xe21a; &#xe219; &#xe21b;
&#xe02f; &#xe024; &#xe025; &#xe026; &#xe027; &#xe028; &#xe029;
&#xe02a; &#xe02b; &#xe02c; &#xe02d; &#xe02e; &#xe332; &#xe333;
&#xe24e; &#xe24f; &#xe537;        

转载地址:http://pukupi.com/post/1964/

你可能感兴趣的:(ios,list,iPhone,dialog,character,button)