0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SwiftUIを始めてみました

Last updated at Posted at 2021-04-11

iPhoneアプリに挑戦しようと思って、最近お仕事でStoryboardを用いてアプリを作っています。ただ、いつまでもStoryboardでアプリを作るのも色々大変なので思い切ってSwiftUIの勉強を独学しています。今回は(?)大したことを書いてないのでキャプチャで書いていきます。

まずは初期のソースを色々いじってみることに

SwiftUIプロジェクトの初期ソースがこれです。SwiftUIからはソースをリアルタイムにプレビューできるので便利ですね。

スクリーンショット 2021-04-11 21.55.41.jpg

そして理想のアプリを作るためにソースをいじってみることに。なんだかんだプログラムは割と触ってきたので、「Text」という部分をもう一個下にコピペすれば「Hello, world!」が2行出来るんじゃないかと予測。早速コピペしてみると

スクリーンショット 2021-04-11 21.55.54.jpg

いやいや、なんで画面が2画面出るんだよ・・・💦この時点で挫折しかけました。

(もし、2行にする場合は以下のようにVStackで囲めばいいらしい。)

スクリーンショット 2021-04-11 21.56.10.jpg

VStackで囲った箇所はVertical(垂直)に要素を並べるようです。何故VStackがないと2画面にバラけてしまうかはまだ調べきれてないですが・・・💦これだというものがあったらまとめたいと思います。VStackの他にHStackやZStackみたいに囲えるものがあるのです。HTMLで言うところの「div」に近いなと思いました。最近HTMLの仕事を進めていたこともあって、個人的にはStoryboardよりSwiftUIの方が取っ付き易いなと思いました。また気が付いたことや作ったアプリについてまとめて行きたいと思います。

参考

https://swiftui.i-app-tec.com/ios/vstack-hstack.html
https://developer.apple.com/documentation/swiftui/view
https://tech.uzabase.com/entry/2019/06/05/141605

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?