你怎么用“让newSwiftColor = UIColor(红色:255,绿色:165,蓝色:0,alpha:0)? [英] How do you use " let newSwiftColor = UIColor(red: 255, green: 165, blue: 0, alpha: 0)?
问题描述
我正在编写一个应用程序,其中按钮的边框颜色为#22A7EF的十六进制颜色。在viewDidLoad部分中,我尝试设置边框的颜色,如下所示:
I am writing an app where a button has a border with the hex color of #22A7EF. In the viewDidLoad section, I tried to set the colors of the borders like this:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
animalNumber.delegate = self
weightInKilos.delegate = self
percentOfDehydration.delegate = self
ongoingLosses.delegate = self
factor.delegate = self
let newSwiftColor = UIColor(red: 34, green: 167, blue: 239, alpha: 0)
calcbutton.layer.cornerRadius = 4;
calcbutton.layer.borderWidth = 1;
calcbutton.layer.borderColor = UIColor.newSwiftColor().CGColor
}
我认为这是声明颜色变量的正确方法,但是我应该如何在 calcbutton.layer.borderColor = UIColor.newSwiftColor()中使用该变量.CGColor
部分? Xcode表示对于我刚才显示的代码行,类型UIColor没有成员newSwiftColor。我想我正在错误地实现变量。有人知道或看到我做错了吗?谢谢!
I think that is the correct way to declare a color variable, but how am I supposed to use the variable in the calcbutton.layer.borderColor = UIColor.newSwiftColor().CGColor
part? Xcode says for the line of code I just showed that "type UIColor has no member newSwiftColor". I think I am implementing the variable incorrectly. Does anybody know or see what I did wrong? Thanks!
PS - 在您发表评论或回答之前,请知道
PS- Before you comment or answer, please know that
- 我是一个12岁的孩子,他学到了我所知道的关于在线编程的一切。
- 我浏览了很多网上文章(包括Stack Overflow),但我做了不明白任何答案:(
谢谢!
推荐答案
既然你'重新创建一个包含对UIColor( newSwiftColor
)的引用的新变量,它只是:
Since you're creating a new variable that contains a reference to a UIColor (newSwiftColor
), it would just be:
calcbutton.layer.borderColor = newSwiftColor.CGColor
请注意颜色在UIKit是使用0..1中的浮点数而不是0..255的整数来指定的,因此您需要将所有RGB值除以255.0:
Note that Colors in UIKit are specified using floats from 0..1 not ints from 0..255, so you need to divide all your RGB values by 255.0:
let newSwiftColor = UIColor(red: 34.0/255.0, green: 167.0/255.0, blue: 239.0/255.0, alpha: 0)
这篇关于你怎么用“让newSwiftColor = UIColor(红色:255,绿色:165,蓝色:0,alpha:0)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!