美文网首页iOS Developer
UIAlertController UIAlertView U

UIAlertController UIAlertView U

作者: HarryKun | 来源:发表于2016-11-08 11:30 被阅读155次

    一  ,ios8.0以后的新特性:

    1,今天用到的时候才知道的新特性给大家分享一下;

    2,​UIAlertController = UIAlertView +

    UIAlertSheet

    3,二者合二为一了。​​

    二,下面就用常用的上传头像实例,实战开始使用一下!!!

    UIAlertController *alert = [UIAlertController

    alertControllerWithTitle:@"添加照片" message:nil

    preferredStyle:UIAlertControllerStyleActionSheet];//初始化一个标题为“选择时间”,风格是ActionSheet的UIAlertController,其中"\n"是为了给DatePicker腾出空间

    UIAlertAction *cancel = [UIAlertActionactionWithTitle:@"取消" style:UIAlertActionStyleCancelhandler:^(UIAlertAction *action){       //点击确定按钮的事件处理   }];

    UIAlertAction *camera =[UIAlertAction actionWithTitle:@"拍照"style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){              //执行拍照代码

    UIImagePickerControllerSourceType sourceType =UIImagePickerControllerSourceTypeCamera;

    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])       {           UIImagePickerController *picker = [[UIImagePickerController alloc]init];           picker.delegate =self;           //设置拍照后的图片可被编辑           picker.allowsEditing =YES;

    picker.sourceType =sourceType;

    [self presentViewController:pickeranimated:YES completion:^{}];

    }else

    {

    NSLog(@"模拟其中无法打开照相机,请在真机中使用");

    }

    }];

    UIAlertAction *photo = [UIAlertActionactionWithTitle:@"从相册选择" style:UIAlertActionStyleDefaulthandler:^(UIAlertAction *action){

    //执行从相册选择代码

    UIImagePickerController *picker =[[UIImagePickerController alloc]init];              picker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;       picker.delegate =self;

    //设置选择后的图片可被编辑

    picker.allowsEditing =YES;

    [self presentViewController:picker animated:YEScompletion:^{}];

    }];

    [alert addAction:camera];

    [alertaddAction:photo];

    [alertaddAction:cancel];

    [selfpresentViewController:alert animated:YEScompletion:^{

    }];

    相关文章

      网友评论

        本文标题: UIAlertController UIAlertView U

        本文链接:https://www.haomeiwen.com/subject/esyauttx.html