klick后警报的tintcolor会发生变化

时间:2015-11-03 07:52:55

标签: swift2 ios9

我使用ios 9 swift 2,我想改变警报的按钮色调颜色。这是可以正常工作的代码:

            let alertController = UIAlertController(title: „Title here", message: „Text here.", preferredStyle: .Alert)

        let rateAction = UIAlertAction(title: "Button 1", style: .Default) { (action) in
            print(„OK“)
        }

        let cancelAction = UIAlertAction(title: "Button 2", style: .Default) { (action) in
            print(„Cancel")
        }

        alertController.addAction(rateAction)
        alertController.addAction(cancelAction)
        self.presentViewController(alertController, animated: true) {}
        alertController.view.tintColor = UIColor(red: (122/255.0), green: (165/255.0), blue: (23/255.0), alpha: 1.0)
    }

enter image description here

但如果我将手指放在一个按钮上,您可以看到,tintcolor更改为默认值:

enter image description here

任何想法我怎么能解决这个问题?

1 个答案:

答案 0 :(得分:0)

试试这个:

your_btn.setTitleColor(UIColor.brownColor(), forState: UIControlState.Highlighted)

此外,您可以使用RGBA设置UIColor:

UIColor(red: 255/255, green: 255/255, blue: 255/255, alpha: 1)