Reputation: 624
I created a Swift Playground on my iPad and did all of my graphics positioning on the iPad simulator. Does anyone know how to edit the size of the Xcode playground simulator? Thanks in advance.
Upvotes: 16
Views: 8806
Reputation: 8463
if you're using the SwiftUI on Xcode Playground Simulator when using live view... You can basically set the frame size before setting the Live View.
struct ContentView: View {
var body: some View {
VStack {
Spacer()
Text("Test")
Spacer()
}
.frame(width: 700, height: 700, alignment: .center)
}
}
PlaygroundPage.current.setLiveView(ContentView())
That's it!
Upvotes: 2
Reputation: 273
import PlaygroundSupport
import UIKit
let viewController = UIViewController()
viewController.view.frame = CGRect(x: 0, y: 0, width: 320, height: 568)
PlaygroundPage.current.liveView = viewController
Seems to me this is the only working example at the moment (Xcode 12.5).
Setting the view.frame
is the key here.
Upvotes: 18
Reputation: 6393
let vc = ViewController()
vc.view.frame.size = CGSize(width: 375, height: 667)
PlaygroundPage.current.liveView = vc.view
Upvotes: 5
Reputation: 3287
To change the size of a playground's liveView, set the preferredContentSize of the viewController.
import PlaygroundSupport
import UIKit
let viewController = UIViewController()
viewController.preferredContentSize = CGSize(width: 600, height: 600)
PlaygroundPage.current.liveView = viewController
Upvotes: 18