UIColor Swift 给出了不同的颜色 [英] UIColor Swift gives a different Color

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

问题描述

我正在尝试使用这种颜色

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 " Not an expert of Colors " but it gives me a pink color..

我试过除以 255 如下share.backgroundColor = UIColor(red: 53/255, green: 155/255, blue: 220/255, alpha: 0.5)

i've tried to divide by 255 as follow share.backgroundColor = UIColor(red: 53/255, green: 155/255, blue: 220/255, alpha: 0.5)

但对我不起作用,我是否遗漏了什么或做错了什么?

But didn't work for me, am i missing something or doing something wrong ?

推荐答案

第一个代码不对,就是翻译成1.0,1.0,1.0:

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)

您需要将其除以 255.0 才能得到 0-1.0 的范围,那么您应该会得到正确的结果:

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)

获得粉红色的唯一方法是将其与另一种颜色相结合.问题是,您的背景颜色容易与另一种颜色混合 - 您将不透明度设置为 0.5.因此,与可能在其背后的其他事物相结合是这种行为的一个非常令人信服的理由.将 alpha 设置为 1.0,看看会发生什么.

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.

这篇关于UIColor Swift 给出了不同的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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