2016-09-19 68 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

检查更新后的答案 –