Awesome Open Source
Awesome Open Source

Playground View Controllers

Add the Playground.swift file to the Sources folder in your playground to easily create UIViewControllers for any iPhone or iPad. They assigned to the playground's live view show you can see and interact with your UI. For example, you can create an iPhone 7 Plus view controller in landscape with a navigation bar that contains touchable bar button items.

Example Navigation View Controller


Choose from iPhone 3.5", 4", 4.7", 5.5", iPad, iPad Pro, or TV screen sizes.

let vc = UIViewController(screenType: .phone3_5)


Defaults to portrait, specify landscape as follows:

let vc = UIViewController(screenType: .phone3_5, isPortrait: false)

Navigation Controller

Add a navigation controller to a view controller using:

let vc = UIViewController(screenType: .phone3_5, barVisibility: .withNavigation(isUnderTopBar: false))
vc.title = "iPhone Playground View Controller"

To place the view controller under the top bar:

let imageView = UIImageView(image: UIImage(named: "")
let vc = UIViewController(screenType: .phone3_5, barVisibility: .withNavigation(isUnderTopBar: true)) =
vc.title = "Image Under Top Bar"


Create MyViewController subclass to handle a navigation bar button's touch event.

class MyViewController: UIViewController {
    func tapped(sender: AnyObject) {
        print("bar button tapped")
let vc = MyViewController(screenType: .phone3_5, isPortrait: false, barVisibility: .withNavigation(isUnderTopBar: false))
vc.title = "Thank you vets!"
let barButton = UIBarButtonItem(barButtonSystemItem: .camera, target: vc, action: #selector(vc.tapped(sender:)))
vc.navigationItem.rightBarButtonItem = barButton

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
Swift (95,651
Navigation (1,580
Swift 3 (1,049
Playground (766
Size (179
Related Projects