如何避免在UIButton选择时使用UIControlEvents上的选择器改变文本颜色?
我试图确保我的按钮的文本颜色不会改变,当它是高亮,选择或正常。因为我的选择器,它不起作用。我也尝试过在选择器中更改标题tried的文本颜色,但是它没有起作用。如你所见,当背景颜色高的时候,我需要改变背景颜色.添加控件事件目标是我在选择时更改背景色的唯一方法。
这是我的按钮配置代码:
func setBtn(btn: UIButton) {
setBtnTarget(btn)
btn.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
btn.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Highlighted )
btn.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Selected)
}
func setBtnTarget(btn: UIButton) {
btn.addTarget(self, action: "highlighted:", forControlEvents: UIControlEvents.TouchDown)
btn.addTarget(self, action: "normal:", forControlEvents: UIControlEvents.TouchUpInside)
}
func highlighted(btn : UIButton) {
btn.backgroundColor = UIColor(red:0, green:0.133, blue:0.229, alpha:1)
}
func normal(btn : UIButton) {
btn.backgroundColor = UIColor(red:0, green:0.058, blue:0.099, alpha:1)
}欢迎任何其他工作选择。提前谢谢。
发布于 2016-03-02 08:07:29
这似乎不错,您只需确保您的按钮类型是自定义的。
let btn = UIButton(type: .Custom)https://stackoverflow.com/questions/35741170
复制相似问题