Implementation of "IOS" Custom emoticons

Source: Internet
Author: User

Now many apps have their own custom emoticons, the client may want to implement their own expression of choice, send and display, here I introduce a simple custom expression implementation ideas and code.
The following introduction to the basic can realize the custom expression in chat needs, can be combined to understand:

Resource Preparation:

    • Customize the name of the emoji image.
    • The meaning of each custom expression.
    • emtionmeans.plist:key--expression selector each expression corresponding to the tag value, value--the meaning of each expression.
    • emtions.plist:key--the meaning of each expression, value--each expression corresponding to the picture.

Implementation logic:

    • Initialize the expression selector, mainly based on the above two plist tables to convert each other to get what you need.
      To create a emojiview inherited from UIView, the main code is as follows:

Instantiate a Emojview object to get a selector for a custom table.
Next we need a helper to determine if a string is an expression string and whether it contains an expression in a string. Because the realistic expression needs to use the rich text, generally to the memory and the performance consumes the big, for does not contain the expression the string we still direct uilabel to display is better, especially like the chat layout. Before displaying a chat message, we first determine whether the message contains an expression string, where I use [] to identify, if it contains [], we further through the meaning of the expression in the emtionmeans.plist to compare, see whether the content of this [] is an expression, if both are satisfied , it indicates that the message contains a custom expression.
The main code of the auxiliary device:

Finally we need a label,ios that can show our expression Uilabel obviously can't be used directly, here I used a third party mlemojilabel, use it to do a custom expression display. Direct use will also have problems, because the custom expression of resources, to display their own words need to be modified, but also to do some optimization (directly from the Internet download third party in the return of the expression recognition processing attributed string method of expression string recognition is not very accurate).
However, the invocation is convenient, instantiation Mlemojilabel directly call the following method to display their own custom emoticons:

[self.emojiLabel setEmojiText:self.emojiString];

You may need to dynamically change the height of the label, you need to call the method above to call the following method:

CGSize textSize = [self.emojiLabel sizeThatFits:CGSizeMake(SCREEN_WIDTH - 160, size.height)];

The above code can get the current height based on a fixed width.
Full code click here to get.
Demo Effect:

Implementation of "IOS" Custom emoticons

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.