An App Delegate class with no storyboard
[AppDelegate.swift](以下のように修正)
import UIKit
@UIApplicationMain
class AppDelegate : UIResponder, UIApplicationDelegate {
var window : UIWindow?
func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)
-> Bool {
self.window = UIWindow()
self.window!.rootViewController = UIViewController() // 適用したいViewController
self.window!.backgroundColor = .white
self.window!.makeKeyAndVisible()
return true
}
}
#Subview and Superview
func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)
-> Bool {
self.window = UIWindow()
self.window!.rootViewController = UIViewController()
// subviewsの追加ができる
let mainview = self.window!.rootViewController!.view
let v = UIView(frame:CGRectMake(100,100,50,50))
v.backgroundColor = .red // 小さい四角
mainview.addSubview(v) // main viewに追加
self.window!.backgroundColor = .white
self.window!.makeKeyAndVisible()
return true
}