Created
December 8, 2015 23:37
-
-
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
This file contains 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 characters
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 |
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
Thank you for sharing this, I used your ideas to create a device UIViewController.