UIImagePickerControllerDelegate,UINavigationControllerDelegate
- (void)imageChange:(UIButton *)button{
NSLog(@"调用系统相册");
if (button!=self.button) {
self.isChange=NO;
self.button=button;
}
self.isChange=YES;
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.allowsEditing = YES;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePickerController animated:YES completion:^{}];
}
#pragma mark - 保存图片至沙盒
- (void) saveImage:(UIImage *)currentImage withName:(NSString *)imageName
{
NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.5);
NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
[imageData writeToFile:fullPath atomically:NO];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
[picker dismissViewControllerAnimated:YES completion:^{}];
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self saveImage:image withName:@"currentImage.png"];
NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"currentImage.png"];
if (self.isChange==YES) {
self.savedImage = [[UIImage alloc] initWithContentsOfFile:fullPath];
self.addImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,88,87)];
self.addImageView.layer.masksToBounds=YES;
self.addImageView.layer.cornerRadius=44;
self.addImageView.image=self.savedImage;
[self.button addSubview:self.addImageView];
}else if (self.isChange==NO){
return ;
}
}
原文地址:http://blog.csdn.net/darongzi1314/article/details/43405327