How do you use " let newSwiftColor = UIColor(red: 255, green: 165, blue: 0, alpha: 0)?

后端 未结 1 1480
时光说笑
时光说笑 2021-01-26 02:27

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:

           


        
相关标签:
1条回答
  • 2021-01-26 02:53

    Since you're creating a new variable that contains a reference to a UIColor (newSwiftColor), it would just be:

    calcbutton.layer.borderColor = newSwiftColor.CGColor
    

    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)
    
    0 讨论(0)
提交回复
热议问题