iOS控件之UIAlertView

UIAlertView就是我们常说的警告视图 

作用:提示用户,帮助用户选择


在IOS中主要有2种形式   1.是alert警告 弹出带有震动效果 主要是给用户一个通知
                    2.是ActionSheet 会在屏幕底部滑出 相当于产生一个占屏幕1/3大小的view
                         可以通过该窗口将信息发布到如 微薄  人人等资源上




ActionSheet和AlertView 比较相似都是给用户一个提示信息。它是从底部弹出。它通常用于确认潜 
在的危险或不能撤消的操作,如删除一个数据。  


iOS程序中的Action Sheet就像Windows中的 “确定-取消”对话框一样,用于强制用户进行选择。当用户将要进行的操作具有一定危险时,常常使用Action Sheet对用户进行危险提示,这样,用户有机会进行取消操作。
 




Action Sheet需要多个参数:
(1)initWithTitle:设置标题,将会显示在Action Sheet的顶部
(2)delegate:设置Action Sheet的委托。当Action Sheet的一个按钮被按下后,它的delegate将会被通知,并且会执行这个delegate的actionSheet: didDismissWithButtonIndex方法将会执行。这里,我们将delegate设成self,这样可以保证执行我们自己在ViewController.m写的actionSheet: didDismissWithButtonIndex方法
(3)cancelButtonTitle:设置取消按钮的标题,这个取消按钮将会显示在Action Sheet的最下边
(4)destructiveButtonTitle:设置第一个确定按钮的标题,这个按钮可以理解成:"好的,继续"
(5)otherButtonTitles:可以设置任意多的确定按钮






Alert相当于Windows中的Messagebox,跟Action Sheet也是类似的。不同的是,Alert可以只有一个选择项,而Action Sheet却至少要两个选项。


Alert也要填写很多参数:
 
(1)initWithTitle:设置标题,将会显示在Alert的顶部
(2)message:设置提示消息内容
(3)delegate:设置Alert的委托。这里,我们设成self
(4)cancelButtonTitle:设置取消按钮的标题
(5)otherButtonTitles:与Action Sheet类似
[alert show]这条语句用来显示Alert。



project: UIAlertOrSheetDemo  


new file ...


              name:AlertView
              superclass:UIAlertView


打开  AlertView.m


加入


- (void)dealloc
{
//    NSLog(@"dead : %d", self.tag);
    [super dealloc];
}








打开 AppDelegate.m


加入


#import "AlertView.h"






在  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions


中的    [self.window makeKeyAndVisible];  顶上加入






    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button1.frame = CGRectMake(10, 100, 140, 40);
    [button1 setTitle:@"alertView" forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(showAlertView) forControlEvents:UIControlEventTouchUpInside];
    [self.window addSubview:button1];
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button2.frame = CGRectMake(240-70, 100, 140, 40);
    [button2 setTitle:@"actionSheet" forState:UIControlStateNormal];
    [button2 addTarget:self action:@selector(showActionView) forControlEvents:UIControlEventTouchUpInside];
    [self.window addSubview:button2];






在加入方法






- (void)showAlertView
{                  //第一个是取消按钮 之后是确定按钮
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:@"other1", @"other2", nil] ;
    [alertView show];
    
}


- (void)showActionView
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"title" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"destructive" otherButtonTitles:@"other1", @"other2", @"other3", @"other3", nil] ;
    [actionSheet showInView:self.window];
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值