1. Use HTML to achieve hybrid arrangement of text expressions
The advantage of using HTML to achieve the mixed layout of graphic text is that you don't need to consider the position of the emoticon in the text. You just need to make an HTML by yourself and then load it with uiwebview, then place the wenview on the view, and the color font can be adjusted. However, considering the memory, it is easy to use uitableview for chatting, because the memory is easy to manage, (The table will be automatically released). If you use uiscrollview to load the table, the memory will be increased one by one. You can try it in the demo stage. If a table is used, loading HTML by uiwebview will be delayed. Whether it is local or network, it will flash when you put uiwebview in the cell to refresh the table. Therefore, I personally think that HTML is only suitable for dummies in the demo stage, because uiwebview also occupies a lot of resources. (Here I wrote an example of HTML implementation, which indicates a rough expression. I didn't use uiscrollview when using a table, and I had to keep setting contentsize when using uiscrollview );
Encapsulate htmlCode:
[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];
This is similar, but this is a loop to convert all the expressions into image names. Trouble.
Http://dl.dbank.com/c0xpfcvxk3
Ii. Use uilabel + uiimageview to implement text-and-image Mixing
In my opinion, there is no benefit in using this method, but the legend of this cumbersome method has also been circulated on the Internet. The basic idea of this method is to judge the content to be sent out, the expressions are used for separation. uilabel is used for storage of plain text, and uiimageview is used for storage of the expressions, as long as their locations are well calculated, put them on a uiview and add them to the display area. However, this judgment is still complicated. I don't think there is any bright spot in this method, however, the memory consumption is smaller than the preceding HTML, which is true. It does not flash when it is added to the table. (I have also written an example here. You can check it if it is rough .)
Here is an iPhone method to get the keyboard height in real time. register the two keyboards and send them back. It is recommended that you register and remove the notifications in the "Start edit" and "End edit" sections so that they do not conflict with other similar notifications. (The height of the keyboard is used for the horizontal screen, so the width is used ,)
-(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
3. Use drawrect to achieve mixed layout of graphic text
The advantage of the drawrect method is that the memory can be changed, the font color can also be set flexibly, and the memory consumption is relatively small.
The basic idea of drawrect implementation is: first, you specify the maximum line feed width, then use this width to separate the characters you entered, and put the characters you divided into an array respectively, of course it is not just easy to put. When taking a character, you need to judge the space between the end and the start, because the space at the end of the iPhone will automatically wrap the line and determine whether there is an expression at the end, when you add an emoticon, if the width exceeds the maximum width, you need to save the position of the emoticon and the title of the image in each character segment, and use [String drawinrect: cgrectmake (X, Y, width, heigh) withfont: font]; [Image drawatpoint: cgpointmake (x, x)];
Of course, this is enough if you make a set of pictures of the right size, but if your project needs to adapt to a variety of fonts and emoticons, drawatpoint cannot shrink the image, so here I write a small example that is suitable for multiple fonts and sizes. (here I still have to put a rough small example.) You can understand the code.
Http://dl.dbank.com/c0iaxk6gj8
4. The three20 library achieves mixed layout of graphic text,
the implementation of the three20 library is relatively simple. three20 writes a ttlabel, which is similar to uiwebview and loads HTML files. However, three20 is very powerful in memory control, I wrote an example, but I didn't get it back. I will have the opportunity to make it up later, but I personally think it is simple. You can use Facebook's open-source library directly after it is installed.