UIColor Swift gives a different Color

前端 未结 2 561
臣服心动
臣服心动 2021-01-16 06:04

I\'m trying to use this Color

share.backgroundColor = UIColor(red: 53, green: 155, blue: 220, alpha: 0.5)

Which it supposed to be a light blue \

相关标签:
2条回答
  • 2021-01-16 06:22

    I just did this on some test view controller and I've got the light blue color as expected (Xcode 7 beta 3):

    self.view.backgroundColor = UIColor(red: 53/255.0, green: 155/255.0, blue: 220/255.0, alpha: 0.5)
    

    enter image description here

    0 讨论(0)
  • 2021-01-16 06:29

    The first code is incorrect, that is translated to 1.0, 1.0, 1.0:

    let color = UIColor(red: 53, green: 155, blue: 220, alpha: 0.5)

    enter image description here

    You need to divide it by 255.0 to get it in range 0-1.0, then you should get the right result:

    let color = UIColor(red: 53.0/255.0, green: 155.0/255.0, blue: 220.0/255.0, alpha: 1.0)

    enter image description here

    The only way to get pink with this is combining it with another color. The thing is, that your background color is prone to mixing with another color - you are setting opacity to 0.5. Therefore combining with something else which may be behind it is a very much compelling reason to this behavior. Set the alpha to 1.0 and see what happens.

    0 讨论(0)
提交回复
热议问题