2015-07-22 26 views
0

我在Swift操場上搞亂了,試圖展示內置於Cocoa庫中的不同類型的UIButton。我很好奇,爲什麼這個工程:UIButtonType不能在Swift Playground中顯示

Creating a button that works

然而,這並不:

enter image description here

我在做不同的唯一的事情應該構建他們。第一個,我使用UIButton的構造函數構造;第二個,我創建使用UIButton靜態方法返回anyObject應該是給定類型的按鈕。所以,實際上,他們應該是一樣的,對吧?爲什麼第一個顯示給我,但第二個不顯示?

+0

檢查這個問題和答案:http://stackoverflow.com/a/27637398/3202193 –

回答

0

你可以看到按鈕進入Assistant Editor這樣的:

首先,在你的遊樂場的頂部添加import XCPlayground然後添加以下代碼:

var myButton1 = UIButton.buttonWithType(.Custom) as! UIButton 
myButton1.frame = CGRectMake(0, 0, 300, 100) 
myButton1.backgroundColor = UIColor.redColor() 
myButton1.setTitle("This is a button", forState: .Normal) 
XCPShowView("View Title",myButton1) 

要顯示的助理編輯轉到View>Assistant Editor>Show Assistant Editor

而且你可以看到你的按鈕是這樣的:

enter image description here

希望這會有所幫助。

+0

這確實解決了我的問題,謝謝!然而,我仍然有些困惑,爲什麼它不能像上面那樣快速地顯示出來 - 這個系統對它的解釋是不同的嗎? –

+0

我認爲編譯器正在採取這種不同的方式。這就是爲什麼它沒有顯示你喜歡其他按鈕代碼。 –