Swift: 你好, UIKit!

创建主入口 main.swift:

import UIKit

UIApplicationMain(
    Process.argc, Process.unsafeArgv,
    NSStringFromClass(MainApp), NSStringFromClass(MainAppDelegate)
)

创建 app.swift, 对应 MainAppMainAppDelegate 的实现:

import UIKit

class MainApp: UIApplication {
    override func sendEvent(event: UIEvent) {
        super.sendEvent(event)
    }
}

class MainAppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(app: UIApplication, didFinishLaunchingWithOptions opt: [NSObject: AnyObject]?) -> Bool {

        self.window = UIWindow(frame: UIScreen.mainScreen().bounds)

        self.window!.rootViewController = UIViewController()
        self.window!.backgroundColor = UIColor.whiteColor()
        self.window!.makeKeyAndVisible()

        self.window!.AddSubview {
            let label = UILabel(frame: self.window!.frame)
            label.textAlignment = .Center
            label.text = "你好, UIKit!"
            return label
        }
        
        return true
    }

}

extension UIView {
    func AddSubview(subview: ()->UIView) {
        self.addSubview(subview())
    }
}

运行效果:

Swift: 你好 UIKit.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,267评论 4 61
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,003评论 25 709
  • 今天在《哲思》上看了一篇文章,叫《钟爱一生》,让我感动了好一会儿。 文章写的是两个贫穷小镇里的一个男孩和一个女孩在...
    小黄皇冠阅读 544评论 0 2
  • Alcatraz Alcatraz 是一款 Xcode的插件管理工具,可以用来管理XCode的 插件、模版以及颜色...
    龙马君阅读 564评论 1 1
  • 落叶打窗,风雨萧寂,三日成书。
    清泰阅读 198评论 2 2