UIColor 不适用于 RGBA 值 [英] UIColor not working with RGBA values

查看:37
本文介绍了UIColor 不适用于 RGBA 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码(RGBA 值)更改 UITextField 中的文本颜色,但它只是显示为白色或清晰,我不太确定,因为背景本身是白色的.

I am trying to change the text colour in a UITextField using the following code (RGBA value) however it just appears white, or clear, I'm not too sure as the background is white itself.

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

passwordTextField.returnKeyType = UIReturnKeyType.Done
passwordTextField.placeholder = "Password"
passwordTextField.backgroundColor = UIColor.clearColor()
passwordTextField.borderStyle = UITextBorderStyle.RoundedRect
passwordTextField.font = UIFont(name: "Avenir Next", size: 14)
passwordTextField.textAlignment = NSTextAlignment.Center
passwordTextField.secureTextEntry = true

推荐答案

UIColor 的 RGB 值介于 0 和 1 之间(请参阅 文档指定为从 0.0 到 1.0 的值")

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

您需要将数字除以 255:

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))

还有一点,你不需要创建 CGFloats:

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)

这篇关于UIColor 不适用于 RGBA 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆