您的位置:首页 > 产品设计 > UI/UE

ios 关于UIAlertView与UIActionSheet的区别,以及在使用过程中注意事项

2016-04-11 13:49 761 查看
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"hello"
message:@"I'm Apple"
delegate:self
cancelButtonTitle:@"ok"
otherButtonTitles:nil];
[alert show];
[alert release];


有多个按钮的时候

UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"hello"
message:@"O哈啊"
delegate:self
cancelButtonTitle:@"ok"
otherButtonTitles:@"cancel",@"Ignore",nil ];


UIAlertViewDelegate 中的 

 - (void) alertView:(UIAlertView *)alertview

clickedButtonAtIndex:(NSInteger)buttonIndex 

方法可以知道你点的是那个按钮。

UIActionSheet是从屏幕底部弹起的一个模态对话框,它的使用也很简单


UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"Are you sure?"
delegate:self
cancelButtonTitle:@"No Way!"
destructiveButtonTitle:@"Yes, I'm sure!"
otherButtonTitles:nil];
[actionSheet showInView:self.view];
(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex  代理方法,知道你点击了那个按钮

注意:在iphone和ipad上使用UIActionShee控件t的效果会不一样,在苹果的官方文档中有相关说明:

在ipad上使用UIActionSheet控件改控件不再从底部弹出,而是从屏幕中间弹出与UIAlertView警告框弹出有点类似。效果如图所示,cancelButton按钮文字显示不出来,destructiveButtonTitle按钮文字为红色加粗字体


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: