Skip to content

Instantly share code, notes, and snippets.

@nbasham
Last active May 8, 2017 11:08

Revisions

  1. Norman Basham revised this gist Oct 8, 2016. No changes.
  2. Norman Basham revised this gist Oct 8, 2016. 1 changed file with 0 additions and 4 deletions.
    4 changes: 0 additions & 4 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -12,10 +12,6 @@ public class DeviceViewController : UIViewController {
    case iPad_12_9Inch
    case tv
    }

    override public func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    }

    static public func setup(screenType: ScreenType, scale: CGFloat = 2.0, isPortrait: Bool = true) -> (UIWindow, DeviceViewController) {
    let vc = DeviceViewController()
  3. Norman Basham revised this gist Oct 8, 2016. 1 changed file with 14 additions and 8 deletions.
    22 changes: 14 additions & 8 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ public class DeviceViewController : UIViewController {

    static public func setup(screenType: ScreenType, scale: CGFloat = 2.0, isPortrait: Bool = true) -> (UIWindow, DeviceViewController) {
    let vc = DeviceViewController()
    vc.view.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
    vc.view.backgroundColor = .white
    let screenSize = DeviceViewController.screenTypeSize(screenType, isPortrait: isPortrait)
    let playgroundSize = CGSize.init(width: screenSize.width*scale, height: screenSize.height*scale)
    let w = UIWindow(frame: CGRect(x: 0, y: 0, width: playgroundSize.width, height: playgroundSize.height))
    @@ -29,23 +29,29 @@ public class DeviceViewController : UIViewController {
    }

    static private func screenTypeSize(_ screenType:ScreenType, isPortrait:Bool = true) -> CGSize {
    var size : CGSize
    switch screenType {
    case .iPhone3_5Inch:
    return isPortrait ? CGSize(width: 320, height: 480) : CGSize(width: 480, height: 320)
    size = CGSize(width: 320, height: 480)
    case .iPhone4Inch:
    return isPortrait ? CGSize(width: 320, height: 568) : CGSize(width: 568, height: 320)
    size = CGSize(width: 320, height: 568)
    case .iPhone4_7Inch:
    return isPortrait ? CGSize(width: 375, height: 667) : CGSize(width: 667, height: 375)
    size = CGSize(width: 375, height: 667)
    case .iPhone5_5Inch:
    return isPortrait ? CGSize(width: 414, height: 736) : CGSize(width: 736, height: 414)
    size = CGSize(width: 414, height: 736)
    case .iPad:
    return isPortrait ? CGSize(width: 768, height: 1024) : CGSize(width: 1024, height: 768)
    size = CGSize(width: 768, height: 1024)
    case .iPad_12_9Inch:
    return isPortrait ? CGSize(width: 1024, height: 1366) : CGSize(width: 1366, height: 1024)
    size = CGSize(width: 1024, height: 1366)
    case .tv:
    return CGSize(width: 1980, height: 1020)
    size = CGSize(width: 1980, height: 1020)
    }
    if isPortrait {
    return size
    }
    return CGSize.init(width: size.height, height: size.width)
    }

    }

    let (window, vc) = DeviceViewController.setup(screenType: .iPhone3_5Inch/*, scale: 2.0, isPortrait: true*/)
  4. Norman Basham revised this gist Oct 8, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -48,6 +48,6 @@ public class DeviceViewController : UIViewController {
    }
    }

    let (window, vc) = DeviceViewController.setup(screenType: .iPhone3_5Inch)
    let (window, vc) = DeviceViewController.setup(screenType: .iPhone3_5Inch/*, scale: 2.0, isPortrait: true*/)
    PlaygroundPage.current.liveView = window
    vc.view.backgroundColor = #colorLiteral(red: 0.9529411793, green: 0.6862745285, blue: 0.1333333403, alpha: 1)
    vc.view.backgroundColor = .orange
  5. Norman Basham created this gist Oct 8, 2016.
    53 changes: 53 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    import UIKit
    import PlaygroundSupport

    public class DeviceViewController : UIViewController {

    public enum ScreenType : Int {
    case iPhone3_5Inch
    case iPhone4Inch // includes 5th & 6h gen iPod Touch
    case iPhone4_7Inch
    case iPhone5_5Inch
    case iPad
    case iPad_12_9Inch
    case tv
    }

    override public func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    }

    static public func setup(screenType: ScreenType, scale: CGFloat = 2.0, isPortrait: Bool = true) -> (UIWindow, DeviceViewController) {
    let vc = DeviceViewController()
    vc.view.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
    let screenSize = DeviceViewController.screenTypeSize(screenType, isPortrait: isPortrait)
    let playgroundSize = CGSize.init(width: screenSize.width*scale, height: screenSize.height*scale)
    let w = UIWindow(frame: CGRect(x: 0, y: 0, width: playgroundSize.width, height: playgroundSize.height))
    w.rootViewController = vc
    w.makeKeyAndVisible()
    return (w, vc)
    }

    static private func screenTypeSize(_ screenType:ScreenType, isPortrait:Bool = true) -> CGSize {
    switch screenType {
    case .iPhone3_5Inch:
    return isPortrait ? CGSize(width: 320, height: 480) : CGSize(width: 480, height: 320)
    case .iPhone4Inch:
    return isPortrait ? CGSize(width: 320, height: 568) : CGSize(width: 568, height: 320)
    case .iPhone4_7Inch:
    return isPortrait ? CGSize(width: 375, height: 667) : CGSize(width: 667, height: 375)
    case .iPhone5_5Inch:
    return isPortrait ? CGSize(width: 414, height: 736) : CGSize(width: 736, height: 414)
    case .iPad:
    return isPortrait ? CGSize(width: 768, height: 1024) : CGSize(width: 1024, height: 768)
    case .iPad_12_9Inch:
    return isPortrait ? CGSize(width: 1024, height: 1366) : CGSize(width: 1366, height: 1024)
    case .tv:
    return CGSize(width: 1980, height: 1020)
    }
    }
    }

    let (window, vc) = DeviceViewController.setup(screenType: .iPhone3_5Inch)
    PlaygroundPage.current.liveView = window
    vc.view.backgroundColor = #colorLiteral(red: 0.9529411793, green: 0.6862745285, blue: 0.1333333403, alpha: 1)