Merge pull request #8606 from andyque/fixButtonContentSize

fix button title only content size issue
This commit is contained in:
minggo 2014-10-10 15:23:25 +08:00
commit 01e3ae2c61
2 changed files with 10 additions and 0 deletions

View File

@ -638,6 +638,11 @@ void Button::setPressedActionEnabled(bool enabled)
void Button::setTitleText(const std::string& text)
{
_titleRenderer->setString(text);
if (_ignoreSize)
{
Size s = getVirtualRendererSize();
this->setContentSize(s);
}
}
const std::string& Button::getTitleText() const

View File

@ -37,6 +37,8 @@ bool UIButtonTest::init()
// Create the button
Button* button = Button::create("cocosui/animationbuttonnormal.png");
CCLOG("content size should be greater than 0: width = %f, height = %f", button->getContentSize().width,
button->getContentSize().height);
button->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
button->addTouchEventListener(CC_CALLBACK_2(UIButtonTest::touchEvent, this));
button->setZoomScale(0.4);
@ -632,7 +634,10 @@ bool UIButtonTextOnly::init()
// Create the button
auto button = Button::create();
button->setNormalizedPosition(Vec2(0.5, 0.5));
button->setTitleText("PLAY GAME");
CCLOG("content size should be greater than 0: width = %f, height = %f", button->getContentSize().width,
button->getContentSize().height);
button->setZoomScale(0.3);
button->setPressedActionEnabled(true);
button->addClickEventListener([this](Ref* sender) {