Size size = Director::getInstance()->getVisibleSize();
cocos2d::ui::Text* text = cocos2d::ui::Text::create("TextArea Widget can line wrap","AmericanTypewriter",32);
text->ignoreContentAdaptWithSize(false);
text->setPosition(Vec2(size.width /2,size.height /2));
text->setContentSize(Size(280,150));
text->setTextHorizontalAlignment(TextHAlignment::CENTER);
text->setTouchScaleChangeEnabled(true);
text->setTouchEnabled(true);
text->addTouchEventListener([=](Ref* sender,cocos2d::ui::Widget::TouchEventType type)
{
if (type == cocos2d::ui::Widget::TouchEventType::ENDED)
{
if ((int)text->getContentSize().width == 280)
{
text->setContentSize(Size(380,100));
}
else{
text->setContentSize(Size(280,150));
}
}
}); this->addChild(text);
原文链接:https://www.f2er.com/cocos2dx/340239.html