Yuvraj Agarkar
Yuvraj Agarkar

Reputation: 135

how to resize a view in live playgrounds ?? Xcode

I am planning to create a live playground for coming wwdc scholarships but I have no experience in creating live playgrounds because I have worked with single view apps so far

I actually don't know what size should be the view in my playground and I am not able to resize it can any one tell me how to do that , I have tried the below code but it gives me error and doesn't work please help me and any advice related to wwdc project is appreciated thank you

 let main = viewController()
main.view.frame.size = CGSize(width: 300, height: 600)

this code gives error:= expression failed to parse, unknown error

Please tell me how to resize the view and also how should I do it ??

Upvotes: 1

Views: 518

Answers (2)

Anton V
Anton V

Reputation: 1

When you use navbar it is important to size the NavigationController and not the ViewController.

Like this:

let vc = MyViewController()
let navBar = UINavigationController(rootViewController: vc)
navBar.view.frame = CGRect(x: 0, y: 0, width: 320, height: 568)
PlaygroundPage.current.liveView = navBar

Upvotes: 0

iUrii
iUrii

Reputation: 13788

You should change entire frame or bounds properties to resize the view:

import UIKit
import PlaygroundSupport

class ViewController : UIViewController {
    ...
}

let viewController = ViewController()
viewController.view.frame = CGRect(x: 0, y: 0, width: 300, height: 600)
PlaygroundPage.current.liveView = viewController
PlaygroundPage.current.needsIndefiniteExecution = true

Upvotes: 2

Related Questions