UIActionSheet的使用
来源:互联网 发布:apm2.8源码编译 编辑:程序博客网 时间:2024/06/01 10:19
UIActionSheet 与alertview相似,同样也是弹框提示,不同的地方在于actionsheet是靠底端显示,而alertview是居中显示。
-
- UIActionSheet *actionsheet01 = [[UIActionSheet alloc] initWithTitle:@"按钮点击后我才出现的。" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"知道了", nil nil];
-
- [actionsheet01 showInView:self.view];
-
- UIActionSheet *actionsheet02 = [[UIActionSheet alloc] initWithTitle:@"按钮点击后我才出现的。" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"知道了0", @"知道了1", @"知道了2", @"知道了3", nil nil];
-
- [actionsheet02 showInView:self.view];
-
-
-
-
-
-
- UIActionSheet *actionsheet03 = [[UIActionSheet alloc] initWithTitle:@"选择图片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"相册", @"拍照", nil nil];
-
- [actionsheet03 showInView:self.view];
-
-
- @interface ViewController () <UIActionSheetDelegate>
-
- @end
-
-
- - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- NSLog(@"buttonIndex=%ld", buttonIndex);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];
- BOOL isTakePhoto = [title isEqualToString:@"拍照"];
- BOOL isPhotos = [title isEqualToString:@"相册"];
- if (isTakePhoto)
- {
- NSLog(@"点击了拍照按钮");
- }
- else if (isPhotos)
- {
- NSLog(@"点击了相册按钮");
- }
- else
- {
- NSLog(@"点击了取消按钮");
- }
- }
-
-
-
-
- UIAlertController *actionSheetController = [UIAlertController alertControllerWithTitle:nil message:@"选择图片" preferredStyle:UIAlertControllerStyleActionSheet];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- NSLog(@"点击了取消按钮");
- }];
-
- UIAlertAction *takeAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
- NSLog(@"点击了相册按钮");
- }];
-
- UIAlertAction *photoAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
- NSLog(@"点击了拍照按钮");
- }];
-
- [actionSheetController addAction:cancelAction];
- [actionSheetController addAction:takeAction];
- [actionSheetController addAction:photoAction];
-
- [self presentViewController:actionSheetController animated:YES completion:nil];
0 0