iOS开发(swift):页面跳转之设置第一次运行的界面

本文介绍如何使用SwiftUI构建iOS应用程序的界面。通过AppDelegate文件中的代码示例,详细解释了如何设置程序启动时显示的首个页面,包括使用.storyboard和.xib文件的不同方法。SwiftUI作为苹果推出的新一代用户界面框架,简化了iOS应用的界面设计过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

0.界面回顾

 

1.在AppDelegate文件中添加如下代码

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        window=UIWindow(frame:UIScreen.main.bounds)
        window?.rootViewController = RedViewController()   //通过修改这句话决定程序第一次停留的页面,此处为红色页面(.storyboard)
        //window?.rootViewController = BlueViewController(nibName:"BlueViewController",bundle:nil)   //通过修改这句话决定程序第一次停留的页面,此处为蓝色页面(.xib)
        window?.makeKeyAndVisible()
        return true
    }


}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值