定义各种警告框

这两天一直再看devdiv上面推荐的ios5CookBook,发现了不少好东东,下面又是一个哦!

相信大家在做应用时都经常会用到警告框,来提示用户某一步的操作有误或是某些必须完成的部分。然而在另外一些时候呢,有需要用户输入用户名或密码,其实苹果官方早已为我们定义好了,只需要去调用就ok了,下面先展示几种效果图:

  

下面直接上代码了,相信用过AlertView的朋友都不陌生,就不多做解释了

首先是第一种效果图代码“

 //默认样式
    UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"Rating"
                                                     message:@"Can you please rate our app"
                                                    delegate:self
                                           cancelButtonTitle:[self noButtonTitle]
                                           otherButtonTitles:[self yesButtonTitle], nil];
    [alertView show];

第二种效果图,只需把样式更改即可

  //input样式
    UIAlertView *alertViewInput=[[UIAlertView alloc]initWithTitle:@"信用卡"
                                                          message:@"请输入账号"
                                                         delegate:self
                                                cancelButtonTitle:@"cancel"
                                                otherButtonTitles:@"Ok", nil];
    [alertViewInput setAlertViewStyle:UIAlertViewStylePlainTextInput];
    
    //设定文本框
    UITextField *textField=[alertViewInput textFieldAtIndex:0];//可根据文本框索引设置文本属性
    textField.keyboardType=UIKeyboardTypeNumberPad;
    [alertViewInput show];

第三种效果跟第二种差不多,只不过是带有加密效果,以密文形式出现

 //input样式
    UIAlertView *alertViewInput=[[UIAlertView alloc]initWithTitle:@"信用卡"
                                                          message:@"请输入账号"
                                                         delegate:self
                                                cancelButtonTitle:@"cancel"
                                                otherButtonTitles:@"Ok", nil];
    [alertViewInput setAlertViewStyle:UIAlertViewStyleSecureTextInput];
    
    //设定文本框
    UITextField *textField=[alertViewInput textFieldAtIndex:0];//可根据文本框索引设置文本属性
    textField.keyboardType=UIKeyboardTypeNumberPad;
    [alertViewInput show];

第四种带有用户登录界面的

 //设定用户登录界面
    UIAlertView *alertViewLogin=[[UIAlertView alloc]initWithTitle:@"password"
                                                          message:@"please input "
                                                         delegate:self
                                                cancelButtonTitle:@"cancel"
                                                otherButtonTitles:@"ok", nil];
    [alertViewLogin setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
    
    UITextField *login=[alertViewLogin textFieldAtIndex:0];
    login.placeholder=@"请输入用户名";
    
    [alertViewLogin show];

ok ,大功告成,相信在今后的使用过程中,会令你的app增色些许,同时会减少你很多冗余的代码。其实苹果官方很多东西都为我们设置好了,只是我们没有去挖掘而已,平时还要多去看原汁原味的官方文档哦,yes!加油↖(^ω^)↗

源代码:http://download.csdn.net/detail/jidiao/4722286

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值