【发布时间】:2015-12-23 11:25:41
【问题描述】:
在我为状态highlighted 设置UIButton 的backgroundColor 和textColor 后,将显示以下输出:
这里的问题是按钮的背景与白色文本重叠。我该如何解决这个问题?
我在 tvOS 上也有很多问题,从 Interface Builder 设置背景和文本颜色(不适用于 State Config)。我必须将IB的属性和代码结合起来。
这是我的代码:
if shopNowButton.highlighted == true {
shopNowButton.highlighted = false
shopNowButton.backgroundColor = UIColor.orangeColor()
shopNowButton.setTitleColor(UIColor.whiteColor(), forState: .Highlighted)
}
else {
shopNowButton.highlighted = true
shopNowButton.backgroundColor = UIColor.whiteColor()
shopNowButton.layer.borderWidth = 1
shopNowButton.layer.borderColor = UIColor.orangeColor().CGColor
shopNowButton.setTitleColor(UIColor.orangeColor(), forState: .Normal)
}
【问题讨论】:
-
button.setTitleColor(UIColor.whiteColor(), forState: .Selected) -
您是否为按钮的 TouchUpInside 事件添加了此代码?
-
按钮不会被触摸。它只需要在突出显示时更改其背景颜色。
-
@TeodorCiuraru 按钮不会被触摸,那么这个
UIButton应该是UILabel吗? -
是的。使用 UILabel 它可以工作,但是对于下一页,我仍然需要一个具有该功能的 UIButton。