0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【SwiftUI】で画面全体を入力欄に!TextEditorを使ってメモ機能を実装してみた

Posted at

📖 本文
最近、Core Dataを使ったメモアプリを作っていて、
「Apple純正メモアプリみたいに、画面全体が入力欄になるやつどうやるんだろう?」
と思って調べていたところ、TextEditor で簡単に実現できることを知りました。
🎨 実装のイメージ
以下のようなUIを作ります👇
画面いっぱいに本文を書ける
背景はシステムカラーに合わせて変化
CoreDataに保存できる

💻 コード例
view側
スクリーンショット 0007-10-14 23.39.57.png
スクリーンショット 0007-10-14 23.40.50.png
ModelView側
スクリーンショット 0007-10-14 23.41.33.png

🧩ポイント
✅ TextEditorとは
TextEditor は SwiftUIで複数行のテキスト入力を可能にするUIコンポーネント。
つまり、「TextFieldの複数行版」。
✅ .scrollContentBackground(.hidden)
デフォルトでは灰色の背景が付いているので、これを隠すと純正メモ風になります。

🏁 まとめ
TextEditor で簡単に全画面入力UIを実装できる
.scrollContentBackground(.hidden) で背景を消すと一気に見た目が整う
SwiftUIのUIコンポーネントはシンプルだけど、使いこなすとかなり表現力があると実感しました。
CoreDataとの組み合わせも勉強になるのでおすすめです!

0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?