Self-customizing emoji replacement system emoji keyboard

Source: Internet
Author: User

First, about emoji expression

Support for native emoji emoticons is also growing as iOS system versions are upgraded. Emoji emoticons are a set of encodings for emoji in Unicode code, and, of course, another set of encoding Sbunicode independent of Unicode, both of which are well supported in OS systems. The UI system automatically helps us to escape the encoding into emoticons, for example with Sbunicode code like this:

UILabel * label = [[UILabel alloc]initwithframe:cgrectmake (100, 100, 100, 100)];
Label.font = [Uifont systemfontofsize:25];
Label.text = @ "\ue056";
[Self.view Addsubview:label];

A smiley face will appear on the screen:


Second, the idea of developing the expression keyboard

First, in order to achieve cross-platform, regardless of iOS, Andorid end or web side, have to have a same standard, this standard can be international Unicode encoding, our idea is to encode emoticons Unicode and then transfer, so there are two ways, One is by customizing a set of emoticons, which corresponds to Unicode code one by one, when transcoding, we traverse, converted to Unicode after the transfer, the advantage is that we can ensure that all platforms can use the expression unified. On the iOS side, there can be another way, through the above we know that through the Sbunicode code we can display emoji on the client, and the arrangement of this code is very regular, through this feature, we can traverse the range of Sbunicode code to create the expression, The trouble of omitting the picture material.

The expression Unicode range available in iOS is: 0xe001~0xe05a,0xe101~0xe15a,

0xe201~0xe253,0xe401~0xe44c,0xe501~0xe537.

We can add it to the data source array by traversing the method:

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++) {
Add to Data source array
[DataArray addobject:[nsstring stringwithformat:@ "%c", (Unichar) i]];
}
}

Keyboard placement, can be done by CollectionView, very convenient:

To set up a paging controller, create a background view
Bgview = [[UIView alloc]initwithframe:cgrectmake (0, 0, [UIScreen mainscreen].bounds.size.width, 200)];
Paging Controller
Pagecontrolbottom = [[Uipagecontrol alloc]initwithframe:cgrectmake (0, UIScreen mainscreen].bounds.size.width, 20)];
[Bgview Addsubview:pagecontrolbottom];
CollectionView layout
Uicollectionviewflowlayout * layout = [[Uicollectionviewflowlayout alloc]init];
Horizontal layout
Layout.scrolldirection=uicollectionviewscrolldirectionhorizontal;
Set the size of each emoticon button to 30*30
Layout.itemsize=cgsizemake (30, 30);
Calculate the left and right margins for each partition
float Xoffset = (kscreenwidth-7*30-10*6)/2;
Set the content offset for a partition
Layout.sectioninset=uiedgeinsetsmake (Ten, Xoffset, Xoffset);
ScrollView = [[Uicollectionview alloc]initwithframe:cgrectmake (0, 0, [UIScreen mainscreen].bounds.size.width, 160) Collectionviewlayout:layout];
Turn on paging effects
scrollview.pagingenabled = YES;
Set row and column spacing
layout.minimumlinespacing=10;
layout.minimuminteritemspacing=5;

scrollview.delegate=self;
scrollview.datasource=self;
Scrollview.backgroundcolor = Bgview.backgroundcolor;
[Bgview Addsubview:scrollview];

In the CollectionView callback method, the following is handled:

28 Emoticons per page
-(Nsinteger) CollectionView: (Uicollectionview *) CollectionView numberofitemsinsection: (NSInteger) section{
if (((DATAARRAY.COUNT/28) + (dataarray.count%28==0?0:1))!=section+1) {
return 28;
}else{
Return dataarray.count-28* ((DATAARRAY.COUNT/28) + (dataarray.count%28==0?0:1)-1);
}

}
return pages
-(Nsinteger) Numberofsectionsincollectionview: (Uicollectionview *) collectionview{
Return (DATAARRAY.COUNT/28) + (dataarray.count%28==0?0:1);
}
-(Uicollectionviewcell *) CollectionView: (Uicollectionview *) CollectionView Cellforitematindexpath: (NSIndexPath *) indexpath{
Uicollectionviewcell * cell = [CollectionView dequeuereusablecellwithreuseidentifier:@ "biaoqing" ForIndexPath: Indexpath];
for (int i=cell.contentview.subviews.count; i>0; i--) {
[Cell.contentview.subviews[i-1] removefromsuperview];
}
UILabel * label = [[UILabel alloc]initwithframe:cgrectmake (0, 0, 30, 30)];
Label.font = [Uifont systemfontofsize:25];
Label.text =dataarray[indexpath.row+indexpath.section*28];


[Cell.contentview Addsubview:label];
return cell;
}
-(void) CollectionView: (Uicollectionview *) CollectionView Didselectitematindexpath: (Nsindexpath *) indexPath{
NSString * str = dataarray[indexpath.section*28+indexpath.row];
Here, manually add emoji to the TextField

}
Update the paging controller after turning the page
-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{
CGFloat contenoffset = scrollview.contentoffset.x;
int page = contenoffset/scrollview.frame.size.width+ ((int) contenoffset% (int) scrollview.frame.size.width==0?0:1);
pagecontrolbottom.currentpage = page;

}

Three, switch system keyboard and custom emoji keyboard

Both Uitextfield and Uitextview have the following properties and methods:

@property (Nullable, ReadWrite, strong) UIView *inputview;
-(void) reloadinputviews;

Inputview we can set TextView and TextField as the first response when the pop-up attachment, if we do not set or set to nil, it will pop up the system keyboard, Reloadinputview method can let us refresh this attachment view, through the two, We can easily switch the keyboard, for example, we are dealing with a starting method as follows:

-(void) imageviewtap{
if (![ _publishcontent Isfirstresponder]) {
Return
}
if (Isemoji==no) {
Isemoji=yes;
Exhale the expression
_textview.inputview=bgview;
[_textview Reloadinputviews];
}else{
Isemoji=no;
_textview.inputview=nil;
[_textview Reloadinputviews];
}


}

The effect is as follows:

Note: Test the above Sbunicode code in the simulator can display normally, the real machine does not recognize, you can add the emoji to a plist file, through the file read to create a keyboard way to the development of the real computer. The plist file address is as follows :

------------------------------------------Split Line------------------------------------------

Free in http://linux.linuxidc.com/

user name and password are www.linuxidc.com

specific download directory in /2015 profile/December/12th/ios custom emoji emoji keyboard/

Download method See http://www.linuxidc.com/Linux/2013-07/87684.htm

------------------------------------------Split Line------------------------------------------

This article permanently updates the link address : http://www.linuxidc.com/Linux/2015-12/126157.htm

Self-customizing emoji replacement system emoji 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.