嗯啦 發表於 2022-11-7 11:22:49

iOS开发删除storyboard步骤详解

<div id="navCategory"><h5 class="catalogue">目录</h5><ul class="first_class_ul"><li>删除iOS项目中的storyboard</li><ul class="second_class_ul"><li>删除storyboard</li><li>用上自己的ViewController</li></ul></ul></div><p class="maodian"></p><h2>删除iOS项目中的storyboard</h2>
<p>删除项目中的storyboard, (变成一个纯代码的iOS UIKit项目), 需要几步?</p>
<ul><li>找到storyboard, 删掉它.</li><li>直接用ViewController.</li></ul>
<p class="maodian"></p><h3>删除storyboard</h3>
<ul><li>首先, 你得有(新建)一个storyboard项目.</li><li>删除storyboard. 选&quot;Move to Trash&quot;.</li><li>删除plist中的storyboard name.</li></ul>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202211/20221107090907014.png" /></p>
<ul><li>删除deploy target中的Main Interface, 本来是&rdquo;main&rdquo;, 把它变为空.</li></ul>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202211/20221107090907015.png" /></p>
<p>(截图换了一个项目名, 不要在意这些细节.)</p>
<p class="maodian"></p><h3>用上自己的ViewController</h3>
<p>在ViewController里写上自己的完美View. 比如:</p>
<div class="jb51code"><pre class="brush:cpp;">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.
    }
}
</pre></div>
<p>设置新的rootViewController.</p>
<ul><li>在<code>SceneDelegate</code>中设置rootViewController. (iOS 13)</li></ul>
<div class="jb51code"><pre class="brush:cpp;">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()
    }
...
</pre></div>
<ul><li>tvOS没有SceneDelegate (或者你想要兼容iOS 13以前的旧版本):</li></ul>
<div class="jb51code"><pre class="brush:cpp;">import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
    func application(_: UIApplication, didFinishLaunchingWithOptions _: ?) -&gt; Bool {
      window = UIWindow(frame: UIScreen.main.bounds)
      window?.rootViewController = ViewController()
      window?.makeKeyAndVisible()
      return true
    }
...
</pre></div>
<p>运行程序, 看到自己在ViewController里设置的View.</p>
<p>以上就是iOS开发删除storyboard步骤详解的详细内容,更多关于iOS删除storyboard步骤的资料请关注琼殿技术社区其它相关文章!</p>
                           
                            <div class="art_xg">
                              <b>您可能感兴趣的文章:</b><ul><li>详解IOS 利用storyboard修改UITextField的placeholder文字颜色</li><li>详解iOS应用使用Storyboard布局时的IBOutlet与IBAction</li><li>iOS应用开发中StoryBoard搭建UI界面的基本使用讲解</li><li>详解iOS开发中使用storyboard创建导航控制器的方法</li><li>iOS开发之使用Storyboard预览UI在不同屏幕上的运行效果</li></ul>
                            </div>

                        </div>
                        <!--endmain-->
頁: [1]
查看完整版本: iOS开发删除storyboard步骤详解