注册

[寒江孤叶丶的CrossApp之旅_06][入门系列]CrossApp控件之Label标...

CrossApp控件之Label标签。什么是AnchorPoint锚点

CALabel是CrossApp中的标签控件,可以用的地方很多,作为一些提示出现很不错,CALabel共有六种对齐方式,
(居上,居中,居下),(局左,居右,居中)这两种需要分开设置。亦可设置锚点的信息。

对于没有没有学习过Cocos2d-x的朋友,锚点理解起来可能有些问题,

锚点是View(Node)的中心点,在设置View坐标时候,锚点会对齐所设置的坐标。缩放以及旋转也都是以锚点为中心执行的。

锚点的设置是从0-1的 也就是说CCPoint(0,0)是左下角,CCPoint(0.5,0.5)是中心,CCPoint(1,1)是右上角,当然CCPoint(0.6,0.4)这样的形式也是允许的。

下边是CALabel的实现代码:



auto winRect = this->getView()->getBounds();
auto size=winRect.size;
auto label =
CALabel::createWithCenter(CCRect(size.width*0.5,size.height*0.5,300,800));
label->setText("Archer's Demo Text Archer's Demo Text Archer's Demo Text Archer's Demo Text");//设置文字
label->setAnchorPoint(CCPoint(0.5, 0.5));//设置锚点
label->setTextAlignment(CATextAlignmentCenter);//设置对齐方式
label->setColor(CAColor_blue);//设置字色
label->setFontSize(28);//设置字体大小
label->setNumberOfLine(3);//设置最多为3行
label->setFontName("Arial");//设置字体
this->getView()->addSubview(label);//将label添加到view中

已邀请:

要回复问题请先登录注册