Swift playgrounds with UIImage

前端 未结 11 1896
轻奢々
轻奢々 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:25

    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.

提交回复
热议问题