Does swift playground support UIKit?

前端 未结 10 1214
花落未央
花落未央 2020-12-07 23:54

I tried to create a UILabel in playground but failed. Does playground only support OS X development for now?

10条回答
  •  星月不相逢
    2020-12-08 00:28

    YES, it does!

    File: New > File... > iOS > Source > Playground

    import UIKit
    let lbl = UILabel(frame: CGRectMake(0, 0, 300, 100))
    lbl.text = "Hello StackOverflow!"
    

    Then, save the file. This will trigger the Playground to interpret UI related things. Sometimes you may need to toss in a trailing newline and save again -- its a beta. At this point, the word "UILabel" should appear on the right-hand side.

    ios playground quickview

    Now, to actually view what you've done, you've got to click on the "Quick View" eye on the right, or the white circle to open it in Assistant Editor:

    Here's a screenshot of some basic things with UIImage working, etc. ios playground example

提交回复
热议问题