title: Gradient color as a Background color of UIButton in Swift4
body: <p>I have a button and i'm trying to set its background color gradient.I have three hex values which i converted to RGB and written three values in my code and pass all the three values to the button frame. But when i run the app button background not changes according to the color i have set in the code. My code to get three color codes is this,</p>
  
  <pre><code> let gradientColor = CAGradientLayer()
      gradientColor.frame = loginButton.frame
      let color1 = UIColor(red: 183, green: 46, blue: 79, alpha: 1)
      let color2 = UIColor(red: 232, green: 79, blue: 80, alpha: 1)
      let color3 = UIColor(red: 145, green: 21, blue: 79, alpha: 1)
      gradientColor.colors = [color1,color2,color3]
      self.loginButton.layer.addSublayer(gradientColor)
  </code></pre>