cocos2d x 3.0 - Get the size of wrapped text in Label -
if create label in 500x500 area wordwrap, how can find out height of wrapped text ? i'm looking yellow height, not salmon height.
answer of @idrise doesn't work system font , here give more flexible answer.
assume want create text/label has fixed width, dynamic height according text's length. can use below code:
label *lbl = label::createwithsystemfont("aaa aaa aaa aaa aaa aaa", "arial", 50); lbl->setdimensions(fixed_width, 0); // "0" means don't care wrapping vertically, hence `getcontentsize().height` give dynamic height according text's length //// auto dynamicheight = title->getcontentsize().height; // according text's length :)
and fixed height can similarly.
hope :]
Comments
Post a Comment