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

IOS 开发学习十六 UIActionSheet的使用

2015-05-20 10:14 495 查看
1.修改头文件,

@interface WasherFunsContentViewController : UIViewController<UIActionSheetDelegate>{

}


2.事件:

- (IBAction)showSheet:(id)sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"title,nil时不显示"
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:@"确定"
otherButtonTitles:@"第一项", @"第二项",nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;//黑底白字
// UIActionSheetStyleBlackTranslucent透明底白字
// UIActionSheetStyleDefault 灰底白字
[actionSheet showInView:self.view];
//使用Toolbar时,代码像下面这样写
//[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
//[sheet showInView:[AppDelegate sharedDelegate].tabBarController.view]
}


3.委托获取点击

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
NSLog(@"确定");
}else if (buttonIndex == 1) {
NSLog(@"第一项");
}else if(buttonIndex == 2) {
NSLog(@"第二项");
}else if(buttonIndex == 3) {
NSLog(@"取消");
}

}
- (void)actionSheetCancel:(UIActionSheet *)actionSheet{
NSLog(@"cancel");
}
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
NSLog(@"didDismiss");
}
-(void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex{
NSLog(@"willDismiss");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: