Get the system's emoji emoji custom keyboard

Source: Internet
Author: User

First of all, want to get the system's expression, to first know the expression corresponding to the UTF8 encoding, I will part of the picture Show, and then with the UIButton arrangement, IOS 7 added more than 300 emoji, these can be Baidu found, now on the code:

Convert numbers to

#define EMOJI_CODE_TO_SYMBOL (x) ((((0x808080f0 | (x & 0x3f000) >> 4) | (x & 0XFC0) << 10) | (x & 0x1c0000) << 18) | (x & 0x3F) << 24);

The defined macro turns into UTF8 and takes out the corresponding emoji:

Get the default emoticon array

-(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;

}

In the corresponding array of expressions in order to store the expression in UIButton, put out some code:

Get array

Nsarray *arremotion = [self defaultemoticons];

Put the expression in the UIButton.

CGFloat W = 30;

CGFloat H = 30;

CGFloat X;

CGFloat Y;

for (int i = 0; I count; i + +) {

X = ten + (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];

}

This completes the expression added to your custom keyboard and sets the Click event to add the emoji to the TextField or label:

-(void) Biaoqingclick: (UIButton *) biaoqing{

Nsarray *emoji = [self defaultemoticons];

NSString *str = Emoji[biaoqing.tag];

Self.textField.text = str;

}

Basic ability to complete, show: In the background server processing emoticons, after MySQL 5.4 can automatically recognize UICode expression encoding, and verified that the iOS side of the emoji on the Android can also be recognized, if the MySQL version is too low, error unrecognized UICode code, See the server-side blog for emoji Support: http://segmentfault.com/a/1190000000616820 is not finished, follow-up post to make a similar custom expression display way.

Get the system's emoji emoji custom keyboard

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.