当前位置:K88软件开发文章中心编程语言APP编程CrossApp → 文章内容

CATextField(输入框1.2以前版本)

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-23 13:52:55

* loginBtn = CAButton::createWithFrame(DRect(200, 260, 100, 40), CAButtonType::CAButtonTypeRoundedRect); loginBtn->setTitleForState(CAControlStateAll, UTF8("登录")); loginBtn->addTarget(this, CAControl_selector(FirstViewController::login), CAControlEventTouchDown); this->getView()->addSubview(loginBtn);} void FirstViewController::viewDidUnload(){ // Release any retained subviews of the main view. // e.g. self.myOutlet = nil;} bool FirstViewController::onTextFieldAttachWithIME(CATextField * sender){ //获得焦点 CCLog("onTextFieldAttachWithIME--->"); //如果为false获得焦点时不弹出键盘 return false;} bool FirstViewController::onTextFieldDetachWithIME(CATextField * sender){ //失去焦点 CCLog("onTextFieldDetachWithIME--->"); //失去焦点时不移除键盘 return true;} bool FirstViewController::onTextFieldInsertText(CATextField * sender, const char * text, int nLen){ //输入时调用 CCLog("onTextFieldInsertText--->Text:%s,Len:%d", text, nLen); //如果为true,控件则不会接受输入的字符 return true;} bool FirstViewController::onTextFieldDeleteBackward(CATextField * sender, const char * delText, int nLen){ //删除字符时调用 CCLog("onTextFieldDeleteBackward--->Text:%s,Len:%d",delText,nLen); //如果为true,控件则不删除受输入的字符 return false;} //登录void FirstViewController::login(CAControl* control, DPoint point){ //根据tag值获得nameTF 和passwordTF CATextField* nameTF = (CATextField*) this->getView()->getSubviewByTag(1); CATextField* passwordTF = (CATextField*) this->getView()->getSubviewByTag(2); //获得输入框的内容 string name = nameTF->getText(); string password = passwordTF->getText(); //如果用户名为"9miao" 密码为"123456" 则打印ok否则打印error if (strcmp(name.c_str(), "9miao") == 0 && strcmp(password.c_str(), "123456") == 0) { CCLog("OK"); } else { CCLog("ERROR"); }}这样我们就实现了一个最简单的登录页面,通过这个demo能过让更好的理解CATextField的使用方法。CATextField 属性介绍      BackgroundView类型:CAView*解释:设置TextField的背景视图。set/get{}。CursorColor类型:CAColor4B解释:设置TextField的光标颜色。set/get{}。FontName类型:std::string解释:设置TextField的字体名称。set/get{}。FontSize类型:int解释:设置TextField的字体大小。set/get{}。HoriMargins类型:int解释:设置TextField的水平边缘。set/get{}。InputType类型:eKeyBoardInputType解释:设置TextField的输入类型。set/get{}。enum eKeyBoardInputType{ KEY_BOARD_INPUT_NORMAL = 1, //正常输入法 KEY_BOARD_INPUT_PASSWORD, //密码输入法};PlaceHolder类型:std::string解释:PlaceHolder文本内容。set/get{}。SpaceHolderColor类型:CAColor4B解释:PlaceHolder文本内容颜色。set/get{}。Text类型:std::string解释:设置TextField的文本内容。set/get{}。TextColor类型:CAColor4B解释:设置TextField的文字颜色。set/get{}。TextEditAlign类型:eTextEditAlign解释:设置TextField的文本编辑对齐。set/get{}。CharCount类型:int解释:获取TextField的字符计数。get{}。    Delegate类型:CATextFieldDelegate*解释:设置TextField的代理(设置代理才能被监听状态)。set/get{}。VertMargins类型:int解释:设置TextField的垂直边缘。set/get{}。CATextField 方法介绍inline void setKeyboardType (eKeyBoardType type);返回值:参数:类型参数名说明eKeyBoardTypetype键盘类型解释:设置键盘的类型enum eKeyBoardType{ KEY_BOARD_TYPE_NORMAL = 0, //正常键盘 KEY_BOARD_TYPE_NUMBER, //数字键盘 KEY_BOARD_TYPE_ALPHABET, //字母键盘};inline int getKeyboardType ();返回值:inline int参数:解释:获取键盘类型(真机或模拟器上有效)inline void setKeyboardReturnType (eKeyBoardReturnType type);返回值:参数:类型参数名说明eKeyBoardReturnTypetype键盘类型解释:<p style="text-indent: 0em;">enum eKeyBoardReturnType<br>{<br> KEY_BOARD_RETURN_DONE = 21, //确认键为完成<br> KEY_BOARD_RETURN_SEARCH, //确认键为搜索<br> KEY_BOARD_RETURN_SEND, //确认键为发送<br> KEY_BOARD_RETURN_ENTER, //确认键为进入<br>};<br></p>inline int getKeyboardReturnType ();返回值:inline int参数:解释:获取确认键的类型(真机或模拟器上有效) virtual bool resignFirstResponder();返回值:bool参数:解释:隐藏键盘第一响应者状态virtual bool becomeFirstResponder();返回值:bool参数:解释:弹出键盘第一响应者状态virtual void resignResponder();返回值:void参数:解释:隐藏键盘状态static CATextField* createWithFrame(const DRect& frame);返回值:CATextField*参数:类型参数名说明const DRect& frame区域大小解释:创建,并指定其Framestatic CATextField* createWithCenter(const DRect& rect);返回值:CATextField* 参数:类型参数名说明const DRect& rect中心点的位置及大小解释:创建,并指定其Centerbool init();返回值:bool参数:解释:初始化virtual void setImageRect(const DRect& rect);返回值:void参数:类型参数名说明const DRect&rect大小解释:设置图像大小virtual void updateImageRect();返回值:void参数:解释:更新图像void setColor(const CAColor4B& var);返回值:void参数:类型参数名说明const CAColor4B&var颜色值解释:设置颜色const CAColor4B& getColor();返回值:CAColor4B& 参数:解释:获取颜色

上一页  [1] [2] 


CATextField(输入框1.2以前版本)