UIAlertController UIAlertView UIAlertSheet

一  ,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:^{

}];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容