How to change Color of button2 in swift when button1 is clicked?

后端 未结 3 1229
礼貌的吻别
礼貌的吻别 2021-01-24 01:50

All I want to do is change the backgroundColor of fiveMinButton and tenMinButton when fiveMinButton is clicked. Why doesn\'t this code work? @IBAction

3条回答
  •  滥情空心
    2021-01-24 02:45

    If button type rounded rect ..Color cannot be applied. So set the button to type custom and good to go

    self.myButton.backgroundColor = UIColor.redColor()
    

    or you can set the background image or image to the button to gain the color

    self.myButton.setBackgroundImage(UIImage.imageNamed("myButtonImage.png"), forState: UIControlStateNormal)
    

    or

    self.myButton.setImage(UIImage.imageNamed("myButtonImage.png"), forState: UIControlStateNormal)
    

提交回复
热议问题