×

一、简介与环境搭建

CrossApp简介CrossApp摘要CrossApp坐标系浅谈CrossApp屏幕适配方案CrossApp源码结构CrossApp的MVC模式CrossApp项目结构及入口CrossApp内存管理CrossApp类结构图创建CrossApp工程CAVector、CAList、CADeque、CAMap(数据容器)Windows 开发下VS2013环境搭建Windows 开发下Android环境配置Mac OS 开发下Xcode环境搭建Mac OS 下iOS移植android环境配置

二、CrossApp简单控件的使用

DLayout(自适应布局)CALabel(显示文本)CAImage、CAImageView(显示一张图片)CAScale9ImageView(九宫格图片拉伸)CAButton(按钮)CATextView(多行输入框)CATextViewDelegateCASwitch(开关控件)CAProgress(进度条)CAAlertView(提示框)CAScrollView(滚动视图)CAScrollViewDelegateCAListView(列表)CAListViewDataSourceCAListViewDelegateCATableView(表单视图)CATableViewDataSourceCATableViewDelegateCATableViewCellCACollectionView(容器)CACollectionViewDataSourceCASlider(滑动条)CAStepper(步进控件)CAPageView(页面切换)CAPageViewDelegateCAWaterfallView(瀑布流控件)CAWaterfallViewDataSourceCAWaterfallViewDelegateCAWaterfallViewCellCATextField(输入框)CATextFieldDelegateCAAutoCollectionView(自动化布局容器)CAAutoCollectionViewDataSourceCAAutoCollectionViewDelegateCAVideoPlayerControlView(视频播放器控制视图)CAVideoPlayerControlViewDelegateCAWebView(Web视图控件)CAWebViewDelegateCAGifView(显示Gif图片)CARenderImage(图像渲染)CASegmentedControl(分段控制)CAPickerView(视图选择器)CAPickerViewDataSourceCAPickerViewDelegateCAActivityIndicatorView(活动指示器)CrossApp UIEdit(UI编辑器)

三、视图控制

CAViewController(视图控制器)CADrawerController(抽屉控制器)CANavigationController(导航控制器)CANavigationBarDelegateCANavigationBarItemCANavigationBarCATabBarController(标签栏控制器)CATabBarDelegateCATabBarItem

四、调用系统支持

CADevice

五、数据的解析与存储

CAUserDefault简单存储SQlite的使用json解析xml解析

六、网络

网络通信之httphttp请求网络图

七,动画

CAViewAnimation(动画实现)

八、宏定义

宏定义

九、其他控件的使用

CAViewCAViewDelegateCATextField(输入框1.2以前版本)CAObjectCAResponderCAPullToRefreshViewCAControlCAWindowCABarItemCABarButtonItemCASchedulerCAMediaDelegateCAKeypadDelegate

CAAlertView(提示框)


类说明

CAAlertView是提示框控件,如果提示框内的按钮个数不超过三个,这个横向排列按钮,如果按钮个数超过三个则纵向排列。


CAAlertView 方法 (点击方法名可查看方法介绍)

方法 说明
addButton 添加一个按钮到CAAlertView
setAlertMessage 提示框的提示信息 
hide 隐藏提示框
setMessageFontName 提示信息的字体 
show 显示提示框
setTarget 添加监听 
setTitle 提示框的标题
hideWithDisplayed 隐藏提示框
create 创建
createWithText 创建,并指定其Text
initWithText 初始化,并指定化文本
addButton 添加按钮到CAAlertView


CAAlertView是提示框控件,如果提示框内的按钮个数不超过三个,这个横向排列按钮,如果按钮个数超过三个则纵向排列。


我们来看一下实例代码:
首先在.h文件中声明一下函数:

//按钮的回调函数
    void respondTouch(CAControl* btn, DPoint point);
 
//提示框的回调函数
    void alertViewCallback(int btnIndex);

然后在.cpp文件中添加以下代码:

void FirstViewController::viewDidLoad()
{
    //获取屏幕宽度
    DSize size = this->getView()->getBounds().size;
     
    //设置背景颜色为黑色
    this->getView()->setColor(CAColor_black);
     
    //创建Button
    CAButton* imageBtn = CAButton::createWithCenter(DRect(size.width*0.5, 500, 200, 50), CAButtonTypeSquareRect);
     
    //设置Buttion文本
    imageBtn->setTitleForState(CAControlStateAll, "Click");
     
    //设置tag值
    imageBtn->setTag(1);
     
    //设置按钮监听
    imageBtn->addTarget(this, CAControl_selector(FirstViewController::respondTouch), CAControlEventTouchUpInSide);
     
    //添加到屏幕
    this->getView()->addSubview(imageBtn);
}
 
void FirstViewController::respondTouch(CAControl* btn, DPoint point)
{
    //获得屏幕大小
    DSize size = this->getView()->getBounds().size;
     
    //创建CAAlerView 并设置显示文本和 green按钮和yellow按钮
    CAAlertView* alertView = CAAlertView::createWithText("ButtonImage", UTF8("点击替换按钮颜色"), "green", "yellow", NULL);
     
    //获得0-1之间的随机数
    float randNum = CCRANDOM_0_1();
     
    if (randNum > 0.333f)
    {
        //添加按钮设置文本为orange
        alertView->addButton("orange");
    }
    if (randNum> 0.666f)
    {
        //添加按钮并设置文本为blue
        alertView->addButton("blue");
    }
     
    //显示弹窗(如果不调用,弹窗不显示)
    alertView->show();
     
    //设置弹窗按钮的回调
    alertView->setTarget(this, CAAlertView_selector(FirstViewController::alertViewCallback));
}
 
void FirstViewController::alertViewCallback(int btnIndex)
{
    //根据tag获得imageBtn对象
    CAButton* imageBtn =(CAButton*) this->getView()->getSubviewByTag(1);
     
    //根据CAAlertView上按钮的index判断响应的逻辑
    if (btnIndex == 0)
    {                   
        //设置imageBtn背景色为green
        imageBtn->setBackGroundViewForState(CAControlStateNormal, CAView::createWithColor(CAColor_green));
    }
    else if (btnIndex == 1)
    {
        //设置imageBtn背景色为yellow
        imageBtn->setBackGroundViewForState(CAControlStateNormal, CAView::createWithColor(CAColor_yellow));
    }
    else if (btnIndex == 2)
    {
        //设置imageBtn背景色为orange
        imageBtn->setBackGroundViewForState(CAControlStateNormal, CAView::createWithColor(CAColor_orange));
    }
    else
    {
        //设置imageBtn背景色为blue
        imageBtn->setBackGroundViewForState(CAControlStateNormal, CAView::createWithColor(CAColor_blue));
    }
}

CAAlertView 方法说明

void setMessageFontName(std::string &var);

返回值:void

参数:

类型 参数名 说明
std::string var 信息文字

解释:设置提示信息的字体


void setTitle(std::string var, CAColor4B col);

返回值:void

参数:

类型 参数名 说明
CAColor4B col 标题颜色
std::string var 信息文字

解释:设置提示框的标题


void setAlertMessage(std::string var, CAColor4B col);

返回值:void

参数:

类型 参数名 说明
CAColor4B col 提示信息颜色
std::string var 提示信息字体

解释:设置提示框的提示信息


void addButton(const std::string& btnText, CAColor4B col = ccc4(3, 100, 255, 255), CAImage* pNormalImage = NULL,AImage* pHighlightedImage = NULL);

返回值:void

参数:

类型 参数名 说明
std::string& btnText 按钮文字
CAColor4B col 按钮颜色
CAImage* pNormalImage 按钮图像
AImage* pHighlightedImage 高亮度图像

解释:添加一个按钮到CAAlertView


void setTarget(CAObject* target, SEL_CAAlertBtnEvent selector);

返回值:void

参数:

类型 参数名 说明
CAObject* target 监听目标
SEL_CAAlertBtnEvent selector 监听选择器

解释:设置 CAAlertView 的监听


void show();

返回值:void

参数:

解释:设置显示提示框


void hide();

返回值:void

参数:

解释:设置隐藏提示框void


static bool hideWithDisplayed();

返回值:static bool

参数:

解释:隐藏提示框


static CAAlertView* create();

返回值:static CAAlertView*

参数:

解释:创建


static CAAlertView* createWithText(const char* pszTitle, const char* pszAlertMsg, const char* pszBtnText, ...);

返回值:CAAlertView*

参数:

类型 参数名 说明
const char* pszTitle 标题
const char* pszAlertMsg 提示框内容
const char* pszBtnText 按钮文本

解释:创建,并指定其Text


bool initWithText(const char* szTitle, const char* szAlertMsg, const char* pszBtnText, ...);

返回值:bool

参数:

类型 参数名 说明
const char* szTitle 标题
const char* szAlertMsg 提示框内容
const char* pszBtnText 按钮文本

解释:初始化并指定化文本


void addButton(CAButton* pBtn);

返回值:void

参数:

类型 参数名 说明
CAButton* pBtn 按钮

解释:添加按钮到CAAlertView


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)