本网站(662p.com)打包出售,且带程序代码数据,662p.com域名,程序内核采用TP框架开发,需要联系扣扣:2360248666 /wx:lianweikj
精品域名一口价出售:1y1m.com(350元) ,6b7b.com(400元) , 5k5j.com(380元) , yayj.com(1800元), jiongzhun.com(1000元) , niuzen.com(2800元) , zennei.com(5000元)
需要联系扣扣:2360248666 /wx:lianweikj
iOS开发删除storyboard步骤详解
冷月葬花魂 · 165浏览 · 发布于2022-11-07 +关注

这篇文章主要为大家介绍了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.


ios

相关推荐

android下vulkan与opengles纹理互通

talkchan · 1173浏览 · 2020-11-23 10:37:39
Android 使用RecyclerView实现轮播图

奔跑的男人 · 2171浏览 · 2019-05-09 17:11:13
微软发布新命令行工具 Windows Terminal

吴振华 · 866浏览 · 2019-05-09 17:15:04
Facebook 停止屏蔽部分区块链广告

· 752浏览 · 2019-05-09 17:20:08
加载中

0评论

评论
分类专栏
小鸟云服务器
扫码进入手机网页