iOS Playground Doesn't Show UI Preview

iOS Playground doesn't show UI preview

Open the preview panel: View > Assistant Editor > Show Assistant Editor

Then in your code:

import PlaygroundSupport
PlaygroundPage.current.liveView = view

Don't forget to give your view a visible frame.


Ps: after Xcode 9, you can create a playground with default view

playground

Swift playgrounds with UIImage

  1. Open the .playground file in Finder.
  2. Create a folder called Resources next to it.
  3. Add any images you want to this folder.
  4. In the playground press opt-cmd-1 to open the File Inspector. You should see the playground on the right. If you don't have it selected, press cmd-1 to open the Project Navigator and click on the playground file.

File Inspector


  1. Under 'Resource Path' choose 'Relative To Playground'
  2. Click the folder icon underneath and choose the Resources folder created earlier.

You should now have a bundle that you can use with the standard NSImage(named:"filename_without_extension"):

Working nsbundle image

Note: Because Xcode will frequently overwrite the .playground folder, I recommend using this method so the resources folder isn't getting constantly deleted and re-created.

Xcode 8.3.2 playground live view rendering doesn't work

You need to enable the assistant editor to see the results.

View > Assistant Editor > Show Assistant Editor

Also see here:
iOS Playground doesn't show UI preview
Sample Image

Xcode 11 beta swift ui preview not showing

To preview and interact with views from the canvas in Xcode, ensure your Mac is running on Catalina MacOS.

https://developer.apple.com/tutorials/swiftui/creating-and-combining-views

Please check apple document in the following URL
https://developer.apple.com/documentation/xcode_release_notes/xcode_11_beta_2_release_notes

Xcode 11 beta supports development with SwiftUI.

Note

Tools for SwiftUI development are only available when running on macOS
Catalina 10.15 beta.

Playground view output only shows black view

UIStackView does not draw directly to the screen, it just sets up constraints for it's arranged subviews and has those subviews draw directly to the screen. It's background color is ignored because it doesn't draw itself to the screen. To get a background color, you can add it as a subview of a UIView.

Additionally, the text labels need to have their color set to something non-black since black text rendered over black background cannot be seen. The following code should create a nice UIStackView of white text on a blue background.

import UIKit
import XCPlayground

let standardFrame = CGRect(x: 0, y: 0, width: 320, height: 480)
let rootView = UIView(frame: standardFrame)
rootView.backgroundColor = UIColor.blueColor()

let stackView = UIStackView(frame: standardFrame)
stackView.distribution = .EqualSpacing
stackView.alignment = .Center

let strings = ["Hello world", "Guten Tag", "Buenos Dias"]

strings.map { str in
let newLabel = UILabel()
newLabel.textColor = UIColor.whiteColor()
newLabel.text = str
return newLabel
}.forEach(stackView.addArrangedSubview)

rootView.addSubview(stackView)
XCPlaygroundPage.currentPage.liveView = rootView

WKWebView doesn't show on Playground

You need to specify frame explicitly (as there is no window)

PlaygroundPage.current.setLiveView(webView().frame(width: 400, height: 300))

Xcode Canvas for SwiftUI previews does not show up

You need to be on Catalina macOS version (10.15), as stated in official tutorial

Be warned: Catalina doesn't support 32-bit applications, some old apps will stop working after update.



Related Topics



Leave a reply



Submit