swift 纯代码模式 运行第一个DemoAPP

Swift 项目初始化

swift工程和OCiOS工程类似,

  1. 新建 Swift 项目
    File -> New -> Project ,选择iOS-APP

  2. Language 选择 Swift ,创建项目

  3. 修改 AppDelegate.swift 代码,创建导航栏和rootViewController。移除AppDelegate里其余方法,只保留如下方法。

class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        self.window = UIWindow(frame: UIScreen.main.bounds);
        let navigationController = UINavigationController(rootViewController: ViewController())
        self.window?.rootViewController = navigationController
        self.window?.backgroundColor = .white
        self.window?.makeKeyAndVisible()
        return true;
    }
}
  1. ViewController.swift为加载的首页,可以在这个页面加点背景颜色和按钮。
import Foundation
import UIKit
class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        self.view.backgroundColor = .red;
        
        let label = UILabel(frame: CGRect(x: 100, y: 200, width: 300, height: 100))
        label.text = "This is First VC";
        label.textColor = .black;
        self.view .addSubview(label);
    }
}
  1. 删除Info.plist文件中的Application Scene Manifest 项。
  2. 然后就可以Run了。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fantongl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值