UIColor not working with RGBA values UIColor not working with RGBA values ios ios

UIColor not working with RGBA values


RGB values for UIColor are between 0 and 1 (see the documentation "specified as a value from 0.0 to 1.0")

You need to divide your numbers by 255:

passwordTextField.textColor = UIColor(red: CGFloat(202.0/255.0), green: CGFloat(228.0/255.0), blue: CGFloat(230.0/255.0), alpha: CGFloat(1.0))

Another thing, you don't need to create CGFloats:

passwordTextField.textColor = UIColor(red:202.0/255.0, green:228.0/255.0, blue:230.0/255.0, alpha:1.0)


Using convenience init ( code like a pro )

Step 1

extension UIColor {    convenience init(r: CGFloat, g: CGFloat, b: CGFloat) {        self.init(red: r/255, green: g/255, blue: b/255, alpha: 1)    }}

Usage

//let color = UIColor(red: 202/255, green: 228/255, blue: 230/255, alpha: 1) ☠️let color = UIColor(r: 202, g: 228, b: 230) // 😍


try this instead :

passwordTextField.textColor = UIColor(red: 0.792, green: 0.894, blue: 0.901, alpha: 1.0

Always put substituted values. 202/255 = 0.792