一。CATextField类的继承关系:
1.19版本,源代码中定义:
class CC_DLL CATextField : public CATouchView , public CAIMEDelegate
二。CATextField类作用:
CATextField是单行输入框控件。主要接收用户的文本输入,多用于用户名、密码、聊天输入等。
二。创建:
实例代码:
void FirstViewController::viewDidLoad() { //创建 提示输入username CALabel* calabelname = CALabel::createWithFrame(CCRect(80, 100, 80, 40)); calabelname->setText(UTF8("用户名:")); calabelname->setTextAlignment(CATextAlignmentRight); //创建 提示输入password CALabel* calabelpasswd = CALabel::createWithFrame(CCRect(80, 150, 80, 40)); calabelpasswd->setText(UTF8("密码:")); calabelpasswd->setTextAlignment(CATextAlignmentRight); getView()->addSubview(calabelname); getView()->addSubview(calabelpasswd); //创建一个textfield 来被用户输入 CATextField* catextfieldname = CATextField::createWithFrame(CCRect(80+80+40, 100, 200, 40)); CATextField* catextfieldpasswd = CATextField::createWithFrame(CCRect(80+80+40, 150, 200, 40)); //设置文本输入的类型 catextfieldpasswd->setInputType(KEY_BOARD_INPUT_PASSWORD); //键盘的类型 catextfieldname->setKeyboardType(KEY_BOARD_TYPE_ALPHABET); catextfieldpasswd->setKeyboardType(KEY_BOARD_TYPE_NUMBER); //设置输入框里的提示 catextfieldname->setPlaceHolder(UTF8("输入用户名")); catextfieldpasswd->setPlaceHolder(UTF8("输入密码")); getView()->addSubview(catextfieldname); getView()->addSubview(catextfieldpasswd); //button CAButton* cabuttonline = CAButton::createWithFrame(CCRect(80+80+40,100+100+40,100,40), CAButtonTypeRoundedRect); cabuttonline->setTitleForState(CAControlStateNormal, "online"); cabuttonline->setTitleForState(CAControlStateHighlighted, "ONLINE"); getView()->addSubview(cabuttonline); //CATextField 事件处理 /* 1. 实例化 CATextFieldDelegate 2. 绑定监听 */ }//效果如下图所示: