網站首頁 編程語言 正文
刪除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-11-18 阿里云kubernetes查找鏡像中jar包的方法(docker查看鏡像中的jar)_云其它
- 2023-01-29 Python?第三方庫?openpyxl?的安裝過程_python
- 2022-10-03 react項目升級報錯,babel報錯,.babelrc配置兼容等問題及解決_React
- 2022-04-22 Golang執行流程詳解,兩種執行流程方式有什么不同
- 2022-12-10 Flutter改變狀態變量是否必須寫在setState回調詳解_Android
- 2021-12-09 C語言實現將double/float?轉為字符串(帶自定義精度)_C 語言
- 2022-06-01 分享Python?加速運行技巧_python
- 2022-05-12 tp5使用阿里云oss存儲圖片
- 最近更新
-
- 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同步修改后的遠程分支