[Android开发学iOS系列] 删除storyboard需要几步
删除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.
Ta-da!
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
2012-11-06 Java用户界面 模型-视图-控制器(MVC)模式