Multi-line display of cclabelttf (Chinese only)

Source: Internet
Author: User

This title is called setdimensions. The reason why I want to get a dialog box function for automatic line feed is that I think of how to automatically line feed.

You can see a function called setdimensions and set the area that can be displayed. If you have found some examples on the internet, it seems that the line feed is really amazing.

However, the new helloworld example found a problem. The Code is as follows:

Cclabelttf * plabel = cclabelttf: Create ("Hello World", "Arial", 24 );
Plabel-> setdimensions (ccsizemake (50, 0); // set the display area
Plabel-> sethorizontalalignment (kcctextalignmentleft); // align horizontally to the left
// Position the label on the center of the screen
Plabel-> setposition (CCP (origin. x + visiblesize. width/2,
Origin. Y + visiblesize. Height-plabel-> getcontentsize (). Height ));
// Add the label as a child to this layer
This-> addchild (plabel, 1 );

The result is as follows:

We can see that there is less ~ If you set the width (ccsizemake (50, 0), the smaller the width, the more powerful it is.

Okay, continue the experiment. If you change "Hello World" to "helloworld", the effect will be different. Remove the spaces in the middle.

This is the result.

There is no line break. Here we can think of spaces as the \ n line break. In this case, English words are not separated.

Let's take a look at the Chinese display.

There is no problem in Chinese display. This is because Chinese is a single word and cannot be connected as English. Therefore, the multi-line display for Chinese is OK.

Therefore, you can use this method to lazy the display of Chinese characters.

What should I do if multiple lines are displayed in English? What should I do if the multi-line display is mixed between Chinese and English?

Let us give you a thought: in general terms, we can only calculate the length based on the encoding. If the length is enough, we can add a line break to the end or re-create a new cclabelttf.

You can combine these to implement line breaks.

 

Reprinted from http://blog.csdn.net/nynyvkhhiiii/article/details/16987899

Multi-line display of cclabelttf (Chinese only)

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.