Skip to content
9miao edited this page Sep 30, 2014 · 2 revisions

CALabel Detailed Description

Class Description

Label text class that is used to display text.

Base Class

CAView

Attribute

Access Modifier

Attribute Name

Description

protected

Text

Label’s text content

protected

fontName

Label’s font

protected

fontSize

Label’s font size

protected

Color

Label’s font color

protected

VerticalTextAlignmet

Text’s vertical alignment mode

protected

TextAlignment

Text’s horizontal alignment mode

protected

NumberOfLine

Label’s number of line

Protected

LabelSize

Label’s current size

Method

Access Modifier

Method Name

Description

Public

visit

 

Public

sizeToFit

 

Attribute Description

Text
Type: string
Description: label’s text content

fontName
Type: string
Description: label’s font

fontSize
Type: usigned int
Description: font size

Color
Type: ccColor4B
Description: font color

VerticalTextAlignmet
Type: CAVerticalTextAlignment
Description: text’s vertical alignment mode, enumeration type.

1

2

3

4

5

6

typedef enum

{

    CAVerticalTextAlignmentTop,

    CAVerticalTextAlignmentCenter,

    CAVerticalTextAlignmentBottom,

} CAVerticalTextAlignment;

First type is vertical alignment at the top, second type is vertical alignment at the center, and third type is vertical alignment at the bottom.

TextAlignment
Type: CATextAlignment
Description: text’s horizontal alignment mode, enumeration type.

1

2

3

4

5

6

typedef enum

{

    CATextAlignmentLeft,

    CATextAlignmentCenter,

    CATextAlignmentRight,

} CATextAlignment;

First type is horizontal alignment at the left, second type is horizontal alignment at the center, and third type is horizontal alignment at the right.

Example:

1

2

3

4

5

6

7

    CALabel* c_Label =

CALabel::createWithCenter(CCRect(size.width*0.5,size.height*0.5,220,500));

    c_Label->setText("CrossApp is a cross platform application engine,developed by 9miao.com");

    c_Label->setTextAlignment(CATextAlignmentCenter);

    c_Label->setColor(CAColor_orange);

    c_Label->setFontSize(28);

    this->getView()->addSubview(c_Label);

![](http://www.9miao.com/ueditor/php/upload/image/20140623/1403526380597803.png)

NumberOfLine
Type: unsigned int
Description: text’s number of line

Example:

LabelSize
Type: CAsize
Description: read-only property, label’s current size, it’s a change value.

Method Description

virtual void visit()
Return value: void
Description: update label

void sizeToFit()
Return value: void
Description: set self-adaptive label width, namely label width changes with text changes.

Clone this wiki locally