Skip to content

Instantly share code, notes, and snippets.

@Pretz
Created December 8, 2015 23:37
Show Gist options
  • Save Pretz/8ce1d4e2c24d8e6a364b to your computer and use it in GitHub Desktop.
Save Pretz/8ce1d4e2c24d8e6a364b to your computer and use it in GitHub Desktop.
UIViewController Playground: because getting a UIViewController/UINavigationController to display properly in a playground is a little non-obvious
import UIKit
let vc = UIViewController()
vc.view.backgroundColor = .whiteColor()
vc.navigationItem.title = "This is a view controller"
let searchController = UISearchController(searchResultsController: nil)
//searchController.searchBar.barTintColor = UIColor(red:0.16, green:0.45, blue:0.72, alpha:1)
//searchController.searchBar.searchBarStyle = .Minimal
searchController.searchBar.barTintColor = UIColor.orangeColor()
searchController.searchBar.tintColor = UIColor.greenColor()
UITextField.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.8)
vc.navigationItem.titleView = searchController.searchBar
let w = UIWindow(frame: CGRect(x: 0, y: 0, width: 320, height: 480))
let nc = UINavigationController(rootViewController: vc)
w.rootViewController = nc
nc.view.frame
//nc.view.frame = CGRectMake(0, 0, 320, 480)
nc.navigationBar.barStyle = .Black
nc.navigationBar.barTintColor = UIColor(red:0.16, green:0.45, blue:0.72, alpha:1)
nc.navigationBar.tintColor = .whiteColor()
nc.view.setNeedsDisplay()
w.makeKeyAndVisible()
w
nc.navigationBar
@nbasham
Copy link

nbasham commented Oct 8, 2016

Thank you for sharing this, I used your ideas to create a device UIViewController.

@zmcartor
Copy link

zmcartor commented May 1, 2019

Thanks so much for this, very helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment