2016-09-19 69 views
1

我有一個按鈕,我在界面構建器中創建突出顯示整個按鈕的按鈕。我沒有在代碼中做任何事情,只需按Ctrl +拖動到我的視圖控制器文件。Xcode - 按鈕突出顯示不一致

enter image description here

然後我還有一個按鈕,我這個代碼編程方式創建。

let goToButton = UIButton() 
goToButton.setTitleColor(UIColor.blackColor(), forState: .Normal) 
goToButton.titleLabel?.font = UIFont(name: "Arial", size: 18) 
goToButton.setTitle("◀︎ Go To Form", forState: .Normal) 
goToButton.backgroundColor = UIColor.whiteColor() 
goToButton.showsTouchWhenHighlighted = true // Should highlight entire button? 

但是看起來像這樣。

enter image description here

我怎樣才能讓這個像從界面生成器按鈕

+2

檢查 –

+1

您的按鈕式GOTOBUTTON =的UIButton(類型:UIButtonType.System)您是否嘗試過不使用showsTouchWhenHighlighted可能工作 –

+0

? – Kevin

回答

2

設置您的按鈕類型Custom或'系統的亮點相匹配,並嘗試一次,改變這種

let goToButton = UIButton() 

let goToButton = UIButton(type:.System) 

let goToButton = UIButton(type:.Custom) 

和隱藏這個

goToButton.showsTouchWhenHighlighted = true 
+0

檢查更新後的答案 –