LoginSignup
2
4

More than 1 year has passed since last update.

【Swift】Storyboardを使わずにコードのみで実装する準備

Last updated at Posted at 2022-05-16

はじめに

たぶんUIKitを使っている人からしたら当たり前の事なのかもしれないですが、
私はUIKit初心者で毎回忘れるので自分用に書き残しておきます。

Storyboardを削除

「Main」を右クリックして「Delete」を選択
スクリーンショット 2022-05-17 0.44.44.png

Move to Trashを選択
スクリーンショット 2022-05-17 0.46.52.png

Move to Trash Remove Reference
完全に削除 Xcodeの参照を削除

おそらくこんな感じの使い分けだと思います。

Infoを編集

Storyboard Nameを削除します。
スクリーンショット 2022-05-17 0.50.28.png

こうなります
スクリーンショット 2022-05-17 0.53.27.png

Mainの削除

「Deployment Info」の「Main Interface」に入力されているMainを削除します。
スクリーンショット 2022-07-06 18.05.46.png

SceneDelegateを編集

②を編集します。
スクリーンショット 2022-05-17 0.54.38.png

これが完成形です
スクリーンショット 2022-05-17 0.56.10.png

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
-    guard let _ = (scene as? UIWindowScene) else { return }

+    if let windowScene = scene as? UIWindowScene {
+        let window = UIWindow(windowScene: windowScene)
+        window.rootViewController = ViewController.init()
+        self.window = window
+        window.makeKeyAndVisible()
+    }
}

おわり

これでコードのみで実装できるようになりました。
StroyboardみたいにUIパーツを配置していく系はとても苦手です。。

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