LoginSignup
0
0

More than 5 years have passed since last update.

No storyboard with Swift(Storyboard無しの場合)

Last updated at Posted at 2017-11-29

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
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0