iOS保存App中的照片到系统相册或自建相册的方法

2020-01-15 14:07:30王旭
易采站长站为您分析iOS保存App中的照片到系统相册或自建相册的方法,示例代码为传统的Objective-C语言写成,需要的朋友可以参考下  

保存照片到系统相册
保存照片到系统相册这个功能很多社交类的APP都有的,今天我们简单讲解一下,如何将图片保存到系统相册(Photo Album)。

1.创建UIImageView

创建UIImageView是为了将照片展示出来,我们是要把UIImage保存到系统相册(Photo Album):

复制代码
#define SCREEN [UIScreen mainScreen].bounds.size

 

self.image = [UIImage imageNamed:@"iOSDevTip"];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN.width - 300) / 2, 70, 300, 150)];
imageView.image = self.image;
[self.view addSubview:imageView];

 

2.创建UIButton

创建UIButton并绑定actionClick:事件:

复制代码
UIButton *button = [[UIButton alloc] init];
button.frame = CGRectMake( 100, 300, SCREEN.width - 200, 40);
[button addTarget:self action:@selector(actionClick:) forControlEvents:UIControlEventTouchUpInside];
[button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor orangeColor]];
[button setTitle:@"SavePhoto" forState:UIControlStateNormal];
[self.view addSubview:button];

 


- (void)actionClick:(UIButton *)button
{

}

 

3.保存照片到系统相册(Photo Album)

在actionClick:方法里调用:

复制代码