Last active
May 8, 2017 11:08
Revisions
-
Norman Basham revised this gist
Oct 8, 2016 . No changes.There are no files selected for viewing
-
Norman Basham revised this gist
Oct 8, 2016 . 1 changed file with 0 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,10 +12,6 @@ public class DeviceViewController : UIViewController { case iPad_12_9Inch case tv } static public func setup(screenType: ScreenType, scale: CGFloat = 2.0, isPortrait: Bool = true) -> (UIWindow, DeviceViewController) { let vc = DeviceViewController() -
Norman Basham revised this gist
Oct 8, 2016 . 1 changed file with 14 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 = .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: size = CGSize(width: 320, height: 480) case .iPhone4Inch: size = CGSize(width: 320, height: 568) case .iPhone4_7Inch: size = CGSize(width: 375, height: 667) case .iPhone5_5Inch: size = CGSize(width: 414, height: 736) case .iPad: size = CGSize(width: 768, height: 1024) case .iPad_12_9Inch: size = CGSize(width: 1024, height: 1366) case .tv: 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*/) -
Norman Basham revised this gist
Oct 8, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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/*, scale: 2.0, isPortrait: true*/) PlaygroundPage.current.liveView = window vc.view.backgroundColor = .orange -
Norman Basham created this gist
Oct 8, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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)