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

CAButton(按钮)

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

由 ?﹏???ζ???﹏﹏? 创建, 最后一次修改 2016-08-29 类说明在app开放中按钮是最常用的控件之一,大家对Button的需要也多种多样,CrossApp提供了CAButton,其使用思路主要是根据状态设置来完成的。CAButton按钮类,主要为了接收用户的点击操作,从而触发特定的事件。CAButton 属性 (点击属性名可查看属性介绍)属性说明AllowsSelected是否可以选择Selected是否被选择TouchClick是否被触摸点击CAButton 方法 (点击属性名可查看属性介绍)方法说明create创建createWithFrame创建,并指定其FramecreateWithCenter创建,并指定其Centerinit初始化setBackGroundViewForState设置Button的背景ViewgetBackGroundViewForState获取Button的背景ViewsetImageForState设置Button的图片(不支持九宫格)getImageForState获取Button的图片(不支持九宫格)setTitleForState设置Button标题的显示文本getTitleForState获取Button标题的显示文本setImageColorForState设置Button的图像颜色和状态setTitleColorForState设置Button的标题颜色和状态setTitleFontName设置Button文本的字体setImageOffset设置图像偏移量setImageSize设置图像大小setTitleOffset设置标题偏移量setTitleLabelSize设置标题标签大小setTitleFontSize设置标题字体大小setControlState设置状态interruptTouchState中断接触状态ccTouchBegan触摸事件开始时的回调函数ccTouchMoved触摸事件中触点移动时的回调函数ccTouchEnded触摸事件结束时的回调函数ccTouchCancelled触摸非正常结束时的回调函数。(例如:电话或锁屏)addTarget添加回调事件removeTarget删除回调事件removeAllTargets删除所有回调事件/* 创建一个Button 参数类型CAButtonType:CAButtonTypeCustom、CAButtonTypeSquareRect、CAButtonTypeRoundedRect CAButtonTypeCustom:默认看不见任何效果,需要自己定义效果 CAButtonTypeSquareRect:矩形边框类型 CAButtonTypeRoundedRect:圆角边框类型*/CAButton* firstButton = CAButton::create(CAButtonTypeRoundedRect); /* 设置Button的状态显示文本 CAControlStateNormal:缺省状态 CAControlStateHighlighted:高亮状态 CAControlStateDisabled:禁用状态 CAControlStateSelected:选中状态 CAControlStateAll:全部状态*/firstButton->setTitleForState(CAControlStateAll,"Button"); /* 设置Button的状态显示文本的颜色*/firstButton->setTitleColorForState(CAControlStateAll, ccc4(0, 0, 0, 255)); //设置Button文本的字体firstButton->setTitleFontName("宋体"); /* 设置Button的状态的背景View*///九宫格图//firstButton->setBackGroundViewForState(CAControlStateAll,CAScale9ImageView::createWithImage("HelloWorld.png")); //设置纯色View//firstButton->setBackGroundViewForState(CAControlStateAll, CAView::createWithColor(CAColor_red)); /* 设置Button的状态的图片(不支持九宫格)*///firstButton->setImageForState(CAControlStateAll,CAImage::create("HelloWorld.png")); /* 设置Button的状态*///firstButton->setControlState(CAControlStateHighlighted); /* 设置Frame(如果不设置Frame,默认是不显示的)*/firstButton->setFrame(DRect(100,100,200,80)); //添加到绘制this->getView()->addSubview(firstButton); /* 设置Button的监听 CAControlEventTouchDown:按下按钮响应 CAControlEventTouchDownRepeat:(未实现预留)双击时响应 CAControlEventTouchMoved:触点在Button范围内移动 CAControlEventTouchMovedOutSide:触点移动到Button范围外 CAControlEventTouchUpInSide:触点在Button范围内抬起 CAControlEventTouchUpSide:Button抬起 CAControlEventTouchValueChanged:此状态在CAButton无效,在CASlider中响应*/firstButton->addTarget(this, CAControl_selector(FirstViewController::callbackDown), CAControlEventTouchDown); //此状态6.0版本未实现//firstButton->addTarget(this, CAControl_selector(FirstViewController::callbackDownRepeat), CAControlEventTouchDownRepeat); firstButton->addTarget(this, CAControl_selector(FirstViewController::callbackMoved), CAControlEventTouchMoved); firstButton->addTarget(this, CAControl_selector(FirstViewController::callbackMovedOutSide), CAControlEventTouchMovedOutSide); firstButton->addTarget(this, CAControl_selector(FirstViewController::callbackUpInSide), CAControlEventTouchUpInSide); firstButton->addTarget(this, CAControl_selector(FirstViewController::callbackUpSide), CAControlEventTouchUpSide); //此状态6.0版本 Button无效//firstButton->addTarget(this, CAControl_selector(FirstViewController::callbackValueChanged), CAControlEventTouchValueChanged); /* 中断监听*///firstButton->interruptTouchState();监听的回调函数也很简单:有两个参数:CAControl* 和DPointCAControl是Button本身DPoint是触点的坐标void FirstViewController::callbackDown(CAControl* control, DPoint point){ CCLog("callbackDown()-->");} void FirstViewController::callbackDownRepeat(CAControl* control, DPoint point){ CCLog("callbackDownRepeat()-->");} void FirstViewController::callbackMoved(CAControl* control, DPoint point){ CCLog("callbackMoved()-->");} void FirstViewController::callbackMovedOutSide(CAControl* control, DPoint point){ CCLog("callbackMovedOutSide()-->");} void FirstViewController::callbackUpInSide(CAControl* control, DPoint point){ CCLog("callbackUpInSide()-->"); //((CAButton*)control)->setTitleForState(CAControlStateAll, "changed");} void FirstViewController::callbackUpSide(CAControl* control, DPoint point){ CCLog("callbackUpSide()-->");} void FirstViewController::callbackValueChanged(CAControl* control, DPoint point){

[1] [2] [3]  下一页


CAButton(按钮)