欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > > 内容正文

iOS开发删除storyboard步骤详解,

来源: 开发者 投稿于  被查看 23763 次 评论:105

iOS开发删除storyboard步骤详解,


目录
  • 删除iOS项目中的storyboard
    • 删除storyboard
    • 用上自己的ViewController

删除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开发删除storyboard步骤详解的详细内容,更多关于iOS删除storyboard步骤的资料请关注3672js教程其它相关文章!

您可能感兴趣的文章:
  • 详解IOS 利用storyboard修改UITextField的placeholder文字颜色
  • 详解iOS应用使用Storyboard布局时的IBOutlet与IBAction
  • iOS应用开发中StoryBoard搭建UI界面的基本使用讲解
  • 详解iOS开发中使用storyboard创建导航控制器的方法
  • iOS开发之使用Storyboard预览UI在不同屏幕上的运行效果

用户评论