Change button background color using swift language

前端 未结 11 2277
暗喜
暗喜 2020-12-08 13:09

I am new to the swift language. Can someone tell me how to change the background color of a button using the swift language?

11条回答
  •  忘掉有多难
    2020-12-08 13:36

    If you want to set backgroundColor of button programmatically then this code will surly help you

    Swift 3 and Swift 4

    self.yourButton.backgroundColor = UIColor.red
    

    Swift 2.3 or lower

    self.yourButton.backgroundColor = UIColor.redColor()
    

    Using RGB

    self.yourButton.backgroundColor = UIColor(red: 102/255, green: 250/255, blue: 51/255, alpha: 0.5)
    

    or you can use float values

    button.backgroundColor = UIColor(red: 0.4, green: 1.0, blue: 0.2, alpha: 0.5)
    

提交回复
热议问题