LoginSignup
9
7

More than 5 years have passed since last update.

【Swift】メモ帳アプリのサンプルコード(画像追加)

Last updated at Posted at 2016-11-16

概要

メモ帳アプリのサンプルコードです。

機能

  • メモ追加
  • メモ編集
  • メモ削除
  • メモ数表示(追加、削除、検索時に変更)
  • メモ追加時間表示
  • メモ検索(インクリメンタルサーチ)
  • 画像追加

前回からの変更点

  • メモに画像追加(Photoライブラリから画像選択)
  • リファクタリング

実装内容(画像追加)

  • 画像追加のカメラアイコンをナビゲーションバー右端に追加
    • UIBarButtonItemにUIBarButtonSystemItem.Cameraを追加
  • 画像追加ボタンタップ時にフォトライブラリに遷移
    • UIImagePickerControllerを利用
  • フォトライブラリで画像選択
    • UIImagePickerControllerDelegate
    • 画像選択完了時のdelegateメソッド(didFinishPickingMediaWithInfo)
  • メモに選択した画像を表示
    • NSTextAttachmentに画像をセット
    • NSAttributedStringでUITextViewに追加
  • メモ一覧に戻る
    • UIImageをNSDataに変換してNSUserDefaultsに保存
  • メモ一覧で各行の右端に小さい画像を表示
    • NSUserDefaultsからNSDataを取得し
    • UIImageに変換後にcellのaccessoryViewにimageをセット

github

結果

サンプル

9
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
7