TextField * TextField = textfield::create ("Input words here", "Arial", 30);
Textfield->setposition (VEC2 (widgetsize.width/2.0f, widgetsize.height/2.0f));
Textfield->addeventlistener (Cc_callback_2 (HelloWorld::textfieldevent, this));
void HelloWorld::textfieldevent(REF * psender, Textfield::eventtype type)
{
Switch (type)
{
Case Textfield::eventtype::attach_with_ime:
{
TextField * TextField = dynamic_cast<textfield*> (Psender);
Size screensize = ccdirector::getinstance ()->getwinsize ();
Textfield->runaction (Ccmoveto::create (0.225f, VEC2 (screensize.width/2.0f, screensize.height/2.0f +textField- >getcontentsize (). height/2.0f));
_displayvaluelabel->setstring (String::createwithformat ("Attach with IME")->getcstring ());
textfield->setmaxlengthenabled (true); Set allowed maximum number limit
Textfield->setmaxlength (3); //Set maximum allowable number to 3
Textfield->setpasswordenabled (TRUE); //settings can be set to password mode
Textfield->setpasswordstyletext ("*"); //Set the occlusion character of the password to *
textfield->setplaceholder ("Input text Here"); Set Placeholder
Textfield->setplaceholdercolor (Color4b::green); //Set placeholder color
Textfield->settextcolor (color4b::red);
If you want to set up line wrapping
Textfield->ignorecontentadaptwithsize (FALSE); //(code required) here is false, if true, the control uses only Getvirtualrenderersize () the size returned by this function, regardless of setcontentsize size
( (label*) (Textfield->getvirtualrenderer ()))->setlinebreakwithoutspace (true); (The most critical code that has to go)
Textfield->setcontentsize (Size (240, 170)); //(code required)
Textfield->settexthorizontalalignment (Texthalignment::left); //Set the alignment of text in horizontal direction
Textfield->settextverticalalignment (Textvalignment::top); //Set the alignment of text in the vertical direction
Alignment Settexthorizontalalignment So we can understand that left is the entire line of text on the right side of the alignment, the whole line of text is aligned by the side,
Alignment Settextverticalalignment We can understand that top is your entire text by the top of the alignment, whereas bottom is the entire text by the bottom of the alignment
Textfield->getvirtualrenderersize (); Can get the actual size of it
((label*) (Textfield->getvirtualrenderer ()))->setlinebreakwithoutspace (true); //Is true, content is more than width and will be wrapped automatically .
}
Break
Case Textfield::eventtype::D etach_with_ime:
{
TextField * TextField = dynamic_cast<textfield*> (Psender);
Size screensize = ccdirector::getinstance ()->getwinsize ();
Textfield->runaction (Ccmoveto::create (0.225f, VEC2 (screensize.width/2.0f, screensize.height/2.0f));
}
Break
Case Textfield::eventtype::insert_text:
Break
Case Textfield::eventtype::D elete_backward:
Break
}
Cocos2d-x3.3final (TextField) common member functions (c + +)