Swift学习笔记(一):创建swift项目

441 阅读1分钟

创建swift项目

  • 打开 Xcode,选择『Create a new Xcode project』
  • 选择『iOS - App』
  • 填写 Product Name 和 Orgnization Identifier,选择『Swift + UIKit』
  • 点击『create
  • 删除 Main.storyboard 文件
  • 选择 TARGETS - General - 清空 Main Interface
  • 在Info.plist中删除 Application Scene Manifest
  • 在AppDelegate.swift中,注释 SceneSession 相关的方法
  • 修改『AppDelegate.swift』,创建 UIWindow
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        //统一设置导航栏样式

        let attrs = NSMutableDictionary()

        attrs.setValue(UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.medium), forKey: NSAttributedString.Key.font.rawValue)

        attrs.setValue(UIColor.black, forKey: NSAttributedString.Key.foregroundColor.rawValue)

        

        let appearance = UINavigationBarAppearance()

        appearance.configureWithOpaqueBackground()

        appearance.backgroundColor = UIColor(colorHex: 0xEEEEEE)

        appearance.titleTextAttributes = attrs as! [NSAttributedString.Key : Any]

        UINavigationBar.appearance().standardAppearance = appearance

        UINavigationBar.appearance().scrollEdgeAppearance = appearance


        //设置主视图window

        window = UIWindow.init(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))

        window?.backgroundColor = .white

        window?.rootViewController = MainTabBarController()

        window?.makeKeyAndVisible()


        return true

    }