網站首頁 編程語言 正文
刪除iOS項目中的storyboard
刪除項目中的storyboard, (變成一個純代碼的iOS UIKit項目), 需要幾步?
- 找到storyboard, 刪掉它.
- 直接用ViewController.
刪除storyboard
- 首先, 你得有(新建)一個storyboard項目.
- 刪除storyboard. 選"Move to Trash".
- 刪除plist中的storyboard name.
- 刪除deploy target中的Main Interface, 本來是”main”, 把它變為空.
(截圖換了一個項目名, 不要在意這些細節.)
用上自己的ViewController
在ViewController里寫上自己的完美View. 比如:
import UIKit class ViewController: UIViewController { override func loadView() { view = UIView() view.backgroundColor = .systemBlue } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } }
設置新的rootViewController.
- 在
SceneDelegate
中設置rootViewController. (iOS 13)
class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). guard let windowScene = (scene as? UIWindowScene) else { return } let window = UIWindow(windowScene: windowScene) window.rootViewController = ViewController() self.window = window window.makeKeyAndVisible() } ...
- tvOS沒有SceneDelegate (或者你想要兼容iOS 13以前的舊版本):
import UIKit @main class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { window = UIWindow(frame: UIScreen.main.bounds) window?.rootViewController = ViewController() window?.makeKeyAndVisible() return true } ...
運行程序, 看到自己在ViewController里設置的View.
原文鏈接:https://juejin.cn/post/7162845393712054285
相關推薦
- 2022-08-03 MongoDB數據庫條件查詢技巧總結_MongoDB
- 2022-08-18 python編寫第一個交互程序步驟示例教程_python
- 2024-04-05 idea使用docker生成鏡像(打包鏡像,導入鏡像,導出鏡像)
- 2022-05-12 小程序滾動穿透解決方案
- 2023-02-17 golang基礎之waitgroup用法以及使用要點_Golang
- 2023-01-21 Python參數解析器configparser簡介_python
- 2022-09-16 Python?docx庫刪除復制paragraph及行高設置圖片插入示例_python
- 2022-10-08 Python中的enum的使用方法_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支