本文介绍了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.DonepasswordTextField.placeholder = "Password"passwordTextField.backgroundColor = UIColor.clearColor()passwordTextField.borderStyle = UITextBorderStyle.RoundedRectpasswordTextField.font = UIFont(name: "Avenir Next", size: 14)passwordTextField.textAlignment = NSTextAlignment.CenterpasswordTextField.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值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-14 09:32