画像をカメラロールに保存するサンプルを以下に作成しました。
サンプルダウンロード
ソースコード
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| //保存する画像ファイル
NSString *_imageName = @"Pandora_640_1136.jpg";
//画像を保存する
- (void)saveButtonEvent
{
//保存する画像を指定
UIImage *image = [UIImage imageNamed:_imageName];
//画像保存完了時のセレクタ指定
SEL selector = @selector(onCompleteCapture:didFinishSavingWithError:contextInfo:);
//画像を保存する
UIImageWriteToSavedPhotosAlbum(image, self, selector, NULL);
}
//画像保存完了時のセレクタ
- (void)onCompleteCapture:(UIImage *)screenImage
didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
NSString *message = @"画像を保存しました";
if (error) message = @"画像の保存に失敗しました";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @""
message: message
delegate: nil
cancelButtonTitle: @"OK"
otherButtonTitles: nil];
[alert show];
}
|
お薦めの参考書
詳解 Swift 改訂版
Swiftのかなり入り込んだところまで解説しながら、実践コードを多数収録しています。応用本になりますので、入門書を読み終えて中級者から上級者に差し掛かる時に読むことをお勧めします。読み物としてだけではなくリファレンスとしても使用できます。