cocos2d-x限制输入文字数量

来源:互联网 发布:后台远程控制软件 编辑:程序博客网 时间:2024/05/17 01:49

继承 CCTextFieldDelegate 实现 virtual bool onTextFieldInsertText(CCTextFieldTTF * pSender, const char * text, int nLen);

bool xx::onTextFieldInsertText(CCTextFieldTTF * pSender, const char * text, int nLen){
    if ('\n' == *text)
    {
        return false;
    }

    // if the textfield's char count more than m_nCharLimit, doesn't insert text anymore.
    if (pSender->getCharCount() > TEXTLEN)
    {
        return true;
    }
    return false;
}


在初始化CCTextFieldTTF 对象的地方调用 “对象”->setDelegate(this);监听 CCTextFieldDelegate 接口


原创粉丝点击