Swift playgrounds with UIImage

前端 未结 11 1877
轻奢々
轻奢々 2020-12-01 01:36

I am working with Xcode 6, and I\'m trying to recreate the code demoed during session 401 \"What\'s new in Xcode 6\". I\'ve added an image to Images.xcassets (called Sample)

11条回答
  •  爱一瞬间的悲伤
    2020-12-01 02:29

    I had some trouble with this also.

    Unfortunately, Chris' answer didn't work for me. I suspect perhaps a later beta release of Xcode 6 may have removed this setting.

    Here's a solution as of Xcode 6.0 beta 4 (6A267N) available 21st July 2014. I would guess that this corresponds to the "Inside playground" option previously. That is where the Resources folder is within the playground package itself.

    Here's how to set this up.

    Using Finder - or if you're like me and use the awesome Path Finder - right select and choose Show Package Contents as follows:

    enter image description here

    That reveals the packages Resources folder:

    enter image description here

    Copying the image files into that folder will do the business:

    let imageNames = ["back-button", "background", "bg_top"]
    let images = imageNames.map { UIImage(named: $0) }
    

    enter image description here

提交回复
热议问题