//营业执照
- (IBAction)yinyezhizhao:(id)sender {
//选择图片来源
self.yinyezhizhaoImg.tag=1;
UIActionSheet*actionSheet;
// 判断是否支持相机
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
actionSheet=[[UIActionSheet alloc]initWithTitle:@"选择一张照片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"立即拍照上传",@"从手机相册选取", nil];
}else{
actionSheet=[[UIActionSheet alloc]initWithTitle:@"选择一张照片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册选择", nil];
}
actionSheet.tag=250;
[actionSheet showFromTabBar:self.tabBarController.tabBar];
}
- (IBAction)shangpujs:(id)sender {
self.yinyezhizhaoImg.tag=2;
UIActionSheet*actionSheet;
// 判断是否支持相机
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
actionSheet=[[UIActionSheet alloc]initWithTitle:@"选择一张照片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"立即拍照上传",@"从手机相册选取", nil];
}else{
actionSheet=[[UIActionSheet alloc]initWithTitle:@"选择一张照片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册选择", nil];
}
actionSheet.tag=250;
[actionSheet showFromTabBar:self.tabBarController.tabBar];
}
- (IBAction)shengfenzheng:(id)sender {
self.yinyezhizhaoImg.tag=3;
UIActionSheet*actionSheet;
// 判断是否支持相机
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
actionSheet=[[UIActionSheet alloc]initWithTitle:@"选择一张照片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"立即拍照上传",@"从手机相册选取", nil];
}else{
actionSheet=[[UIActionSheet alloc]initWithTitle:@"选择一张照片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册选择", nil];
}
actionSheet.tag=250;
[actionSheet showFromTabBar:self.tabBarController.tabBar];
}
#pragma mark-actionsheet delegate 图片来源定义
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (actionSheet.tag==250) {
NSUInteger sourceType = 0;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
switch (buttonIndex) {
case 0:
//拍照
sourceType=UIImagePickerControllerSourceTypeCamera;
break;
case 1:
// 相册
sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
break;
case 2:
//取消
return;
}
}else{
if (buttonIndex == 0) {
//从相册选择
sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
//取消
return;
}
}
//跳转到相机或相册
UIImagePickerController*imageController=[[UIImagePickerController alloc]init];
imageController.delegate=self;
imageController.allowsEditing=YES;
imageController.sourceType=sourceType;
[self presentViewController:imageController animated:YES completion:^{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
}];
}
}
#pragma mark-相机的协议
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage*image=[info objectForKey:UIImagePickerControllerEditedImage];
NSData*imageData=UIImageJPEGRepresentation(image, 0.0000001);
image=[UIImage imageWithData:imageData];
NSData *data;//转图片流
if (self.yinyezhizhaoImg.tag==1) {
[self.yinyezhizhaoImg setImage:image];
[data writeToFile:[PATH stringByAppendingString:@"/PostImages/yinyezhizhaoImg.jpg"] atomically:YES];//将其命名存到沙盒中
}
else if(self.yinyezhizhaoImg.tag==2){
[self.shangpu setImage:image];
[data writeToFile:[PATH stringByAppendingFormat:@"/PostImages/shangpu.jpg"] atomically:YES];
}else
{
[self.shengfenzheng setImage:image];
[data writeToFile:[PATH stringByAppendingFormat:@"/PostImages/shengfenzheng.jpg"] atomically:YES];
}
[picker dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)yinyezhizhao:(id)sender {
//选择图片来源
self.yinyezhizhaoImg.tag=1;
UIActionSheet*actionSheet;
// 判断是否支持相机
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
actionSheet=[[UIActionSheet alloc]initWithTitle:@"选择一张照片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"立即拍照上传",@"从手机相册选取", nil];
}else{
actionSheet=[[UIActionSheet alloc]initWithTitle:@"选择一张照片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册选择", nil];
}
actionSheet.tag=250;
[actionSheet showFromTabBar:self.tabBarController.tabBar];
}
- (IBAction)shangpujs:(id)sender {
self.yinyezhizhaoImg.tag=2;
UIActionSheet*actionSheet;
// 判断是否支持相机
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
actionSheet=[[UIActionSheet alloc]initWithTitle:@"选择一张照片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"立即拍照上传",@"从手机相册选取", nil];
}else{
actionSheet=[[UIActionSheet alloc]initWithTitle:@"选择一张照片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册选择", nil];
}
actionSheet.tag=250;
[actionSheet showFromTabBar:self.tabBarController.tabBar];
}
- (IBAction)shengfenzheng:(id)sender {
self.yinyezhizhaoImg.tag=3;
UIActionSheet*actionSheet;
// 判断是否支持相机
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
actionSheet=[[UIActionSheet alloc]initWithTitle:@"选择一张照片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"立即拍照上传",@"从手机相册选取", nil];
}else{
actionSheet=[[UIActionSheet alloc]initWithTitle:@"选择一张照片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册选择", nil];
}
actionSheet.tag=250;
[actionSheet showFromTabBar:self.tabBarController.tabBar];
}
#pragma mark-actionsheet delegate 图片来源定义
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (actionSheet.tag==250) {
NSUInteger sourceType = 0;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
switch (buttonIndex) {
case 0:
//拍照
sourceType=UIImagePickerControllerSourceTypeCamera;
break;
case 1:
// 相册
sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
break;
case 2:
//取消
return;
}
}else{
if (buttonIndex == 0) {
//从相册选择
sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
//取消
return;
}
}
//跳转到相机或相册
UIImagePickerController*imageController=[[UIImagePickerController alloc]init];
imageController.delegate=self;
imageController.allowsEditing=YES;
imageController.sourceType=sourceType;
[self presentViewController:imageController animated:YES completion:^{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
}];
}
}
#pragma mark-相机的协议
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage*image=[info objectForKey:UIImagePickerControllerEditedImage];
NSData*imageData=UIImageJPEGRepresentation(image, 0.0000001);
image=[UIImage imageWithData:imageData];
NSData *data;//转图片流
if (self.yinyezhizhaoImg.tag==1) {
[self.yinyezhizhaoImg setImage:image];
[data writeToFile:[PATH stringByAppendingString:@"/PostImages/yinyezhizhaoImg.jpg"] atomically:YES];//将其命名存到沙盒中
}
else if(self.yinyezhizhaoImg.tag==2){
[self.shangpu setImage:image];
[data writeToFile:[PATH stringByAppendingFormat:@"/PostImages/shangpu.jpg"] atomically:YES];
}else
{
[self.shengfenzheng setImage:image];
[data writeToFile:[PATH stringByAppendingFormat:@"/PostImages/shengfenzheng.jpg"] atomically:YES];
}
[picker dismissViewControllerAnimated:YES completion:nil];
}