[寒江孤叶丶的CrossApp之旅_07][入门系列]CrossApp中信息框CAAlertView的使用


原创文章,欢迎转载,转载请注明:文章来自[寒江孤叶丶的CrossApp之旅系列]

博客地址:http://blog.csdn.net/qq446569365

    官方的API文档,对于CAAlertView的介绍存在着一些不准确的地方。(也许是我说的不准确,欢迎纠正)

下面简单介绍一下CAAlertView的使用。

CAAlertView中主要由三部分组成,Title,Message 以及Button。

对应这三个部分,有分别设置他们属性的函数。

Title部分:

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

设置标题文字,以及字色

void setTitleImage(CAImage* image);

设置标题的背景团

好像在当前版本(0.3.5)中没有发现单独设置标题字体的函数

Message部分:

void setMessageFontName(std::string var);

设置消息的显示字体

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

设置消息内容文字和字体颜色

void setBackGroundImage(CAImage* image);

设置消息的背景图案

Button部分:

void setAllBtnBackGroundImage(CAControlState controlState,CAImage* image);

设置所有按钮的背景图案

void setAllBtnTextColor(CAColor4B col =CAColor_white);

设置所有按钮的字体颜色

对于Button还有添加Button的方法:

void addButton(conststd::string& btnText, CAColor4B col = CAColor_white, CAImage* pNormalImage =NULL, CAImage* pHighlightedImage =NULL);

参数依次为:按钮文字,按钮字色,按钮图片,以及按钮被点击后的高亮图片

void addButton(CAButton* pBtn);

这种方式需要先定义一个CAButton,再将CAButton添加到CAAlertView中。

有关CAButton的使用方法,请围观我的博客~博客地址

值得一说的是:CAAlertView的Button如果>3个,则会并列排放,>=3则会竖起来排放

将消息框显示出来的函数是:

void show();

记得不要直接加到view中~

下面附上CAAlertView的使用代码:

    //添加信息框CAAlertView
    auto alertView = CAAlertView::create();//创建消息框
    alertView->addButton("btn1");//添加按钮
    alertView->addButton("btn2");
//    alertView->addButton("btn3");
    alertView->setTitle("Title", CAColor_red);//添加Title
    alertView->setAlertMessage("Message",CAColor_white);//添加Message
    alertView->setTarget(this, CAAlertView_selector(MainMenuViewController::clickButton));//设置按钮的点击回调
    alertView->show();//将消息框显示出来
}
void MainMenuViewController::clickButton(int index)
{
    CCLog("You have clicked %d", index);//Btn的index是从零开始 依次递增的
}<span style="font-size:18px;">
</span>
CAAlertView还有一种带参数的创建方法:

CAAlertView* alertView = CAAlertView::createWithText("Title", "Message", "btn1", "btn2", NULL);
//注意这种方式要以NULL结尾




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值