swift Playground 使用細節

playground 在學習語法方面仍是很是方便的。bash

快捷鍵

快速運行           command + shift + enter
運行截止          shift + enter
左側工做區間  command + 0學習

UIKit相關

playground 能夠展現你繪製的視圖,加載圖片等等之類的ui

  1. 繪製UIView視圖
import UIKit
import PlaygroundSupport

let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 200))
view.backgroundColor = UIColor.red
PlaygroundPage.current.liveView = view
複製代碼

須要導入頭文件 PlaygroundSupportspa

  1. 加載圖片 加載圖片前須要先將圖片資源導入項目中去,利用快捷鍵 command + 0 ,展開左側工做區間,將圖片拖入Resource中去

import UIKit
import PlaygroundSupport

let  imgView = UIImageView(image:UIImage(named: "pic"))
PlaygroundPage.current.liveView = imgView
複製代碼

使用多Page

生成以後就會有多個page,原來的文件會在Untitled page 裏面,並且每一個page下面對應有source和Resource兩個文件夾,子Page下面的是不能供其餘page使用的,全局下的能夠供全部使用。3d

相關文章
相關標籤/搜索