SkillAgentSearch skills...

ViewControllerPlayground

Easily create reusable playground UIViewControllers for any iPhone or iPad.

Install / Use

/learn @nbasham/ViewControllerPlayground

README

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

Sizes

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


let vc = UIViewController(screenType: .phone3_5)

Orientation

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: "talk.objc.io")
let vc = UIViewController(screenType: .phone3_5, barVisibility: .withNavigation(isUnderTopBar: true))
imageView.center = vc.view.center
vc.view.addSubview(imageView)
vc.title = "Image Under Top Bar"

Example

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

View on GitHub
GitHub Stars7
CategoryDevelopment
Updated4y ago
Forks1

Languages

Swift

Security Score

75/100

Audited on Jul 14, 2021

No findings