1.声明相册权限
在info.plist文件中添加
<key>NSPhotoLibraryUsageDescription</key>
<string>用于选取照片</string>

2.把view转成UIImage
- -(UIImage*)imageFromView:(UIView*)view{
-
-
- CGSize s = view.bounds.size;
-
-
-
- UIGraphicsBeginImageContextWithOptions(s, NO, [UIScreen mainScreen].scale);
-
- [view.layer renderInContext:UIGraphicsGetCurrentContext()];
-
- UIImage*image = UIGraphicsGetImageFromCurrentImageContext();
-
- UIGraphicsEndImageContext();
-
- return image;
-
-
- }
3.把UIImage保存到系统相册
- - (void)saveImageToPhotos:(UIImage*)savedImage
- {
-
- UIImageWriteToSavedPhotosAlbum(savedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
-
- }
-
-
-
- - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(voidvoid *)contextInfo{
-
- if (error == nil) {
-
-
- NSLog(@"存入手机相册成功");
-
- }else{
-
- NSLog(@"存入手机相册失败");
- }
-
- }
源码链接