The realization and comparison of several kinds of graphics (expressions) and text mixed in the iphone chatting

Source: Internet
Author: User
Tags mixed advantage

Reprinted from: http://www.cnblogs.com/chen1987lei/archive/2012/04/08.html


First, using HTML to achieve the text expression mixed arrangement
The advantage of using HTML to achieve graphic text is that you do not need to consider the position of the expression in the text, you just need to make an HTML, and then load it with UIWebView, and then put Wenview on the view, the color font can be adjusted, but from memory considerations, Chat generally with UITableView do the lowest level of easy, because the memory is easy to manage, (the table will be automatically released), if it is loaded with Uiscrollview, then the memory will be increased by article, the demo phase can try. If you use a table, because UIWebView loading HTML will have a delay, whether it is local or network, so in the cell inside UIWebView refresh the table will have a flashing effect. So the personal feel that HTML to achieve the words only suitable for the demo stage of the Fool, because UIWebView is also a resource. (Here I wrote an example of HTML implementation, the rough expression of meaning, using the table I did not use Uiscrollview, with Uiscrollview to keep setting contentsize);
Code to encapsulate HTML:

[NSString stringwithformat:@] <body style=background-color:transparent><div style=width:%dpx;word-break: break-all><style>a{text-decoration:none;color:00000}</style>%@ </div></body> ", m_ Pnewline,string];

It's like this, but it's a loop that transforms all the expressions into picture names. Trouble.
Http://dl.dbank.com/c0xpfcvxk3
Second, the use of uilabel+uiimageview to achieve picture and text mixed row
In my opinion with this method is not what benefits, but the internet also early spread the legend of this wretched method, the basic idea of this method is to send out the content to do the judgment, with the expression to do the segmentation, is the pure text to use Uilabel to store, expression is used Uiimageview to store, As long as they have their mutual position can be, and finally put them on a uiview, and then add to the place you want to show, but this judgment is more cumbersome, this method I think there is no bright spot, but the memory consumption is smaller than the above HTML, this is true. There is no flicker in the and to the table. (Here I have also written an example, rough will see it.) )
Here is a way to get the keyboard height of an iphone in real time; sign up for two keyboards to come out with a fallback notice. My suggestion is to put in the start edit and end edit inside the registration and remove, so that does not conflict with other similar notifications. (Here is the height of the keyboard when taking the horizontal screen, so the width is taken,)

-(void) Adjustkeyboardshowview: (nsnotification *) Nofi
{

Nsdictionary *info = [Nofi userInfo];
Nsvalue * value;

value = [info Objectforkey:uikeyboardframeenduserinfokey];



Cgsize keyboardendframe = [value cgrectvalue].size;



int keyheight = Keyboardendframe.width;



if (keyheight = = 352) {

}

else if (Keyheight ==406) {

}
}

Http://dl.dbank.com/c0g0nhmja6
Third, the use of drawrect to achieve the mix of graphic text
The advantage of the DrawRect method is that the memory can be changed, the color of the font can be set flexibly, and the memory loss is relatively small.
DrawRect implementation of the basic idea is, first you given the maximum width of the line is how much, and then the width to split the characters you entered, the characters you split into an array, of course, not casually put, take the character when you want to judge the end with the beginning of the space, Because the end of the iphone inside the space will be automatically wrapped, and to determine whether the end of the expression, plus the expression width is more than the maximum width, to determine the position of the expression of each character and the image name also need to be saved, the final drawing of text and pictures with [string Drawinrect:cgrectmake (x, Y, Width, Heigh) Withfont:font]; [Image Drawatpoint:cgpointmake (x,x)];
Of course, if you do a set of appropriate size of the picture is enough, but if your project needs to adapt to a variety of fonts and expression size, drawatpoint can not narrow the picture, so I write here is a suitable for many different sizes of small example, (here still have to put a rough small example, ) code, you know.
Http://dl.dbank.com/c0iaxk6gj8
Four, the THREE20 library realizes the mixed row of the graphic text,

THREE20 Library implementation is relatively simple, Three20 wrote a ttlabel, functions similar to UIWebView, but also loaded like HTML, but the memory control of the very ox X, this I also wrote an example, but did not get back. There's a chance to make it up later, but personally, Facebook's Open Source Library is ready to be used.

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.