UISlider 来表示色谱

发布于 2024-09-17 11:54:35 字数 196 浏览 6 评论 0原文

我有一个 UISlider 应该更新文本标签的颜色。现在我希望用户能够在光谱中的所有颜色之间进行选择(无论如何)。我正在考虑使用这个 UISlider 来表示颜色,当拖动滑块时,值/颜色会发生变化。

我知道频谱不是连续的,例如:[0,0,0]...[255,0,0]...[255,1,0]...[255,255,0]等。 那么:关于如何实现这一点有什么建议吗?

I have a UISlider that is supposed to update the color of a textlabel. Now I want the user to be able to choose between all colors in the spectrum (sort of all anyway). I was thinking of using this UISlider to represent the colors and when dragging the slider the value/color changes.

I know the spectrum is not sequential like: [0,0,0]...[255,0,0]...[255,1,0]...[255,255,0] etc.
So: any tip on how I can implement this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十级心震 2024-09-24 11:54:35

颜色至少是二维或三维的选择。滑块仅提供标量输出。如果您希望仅使用标量参数平滑地更改选择,您可以尝试在某些颜色图表(或其功能表示)上绘制一条路径线,并以参数方式选择该路径上的一个点。

Color is at least a two or three dimensional selection. And a slider only provides a scalar output. If you want a smoothly changing selection using only a scalar parameter, you might try drawing a path line on some color chart (or a functional representation thereof) and select a point on that path parametrically.

偏闹i 2024-09-24 11:54:35

是的,颜色是一个多维值,但有不同的方法来分割这些维度。我认为色调、饱和度、亮度构造函数(而不是 RGB)将为您提供您想要的效果。例如,我经常会使用 [UIColor colorWithHue:生成随机颜色饱和度:1.f 亮度:1.f 阿尔法:1.f]

将色调从 0 线性滑动到 1,饱和度和亮度固定在最清晰(或其他)值。

Yes, color is a multidimensional value, but there are different ways to slice those dimensions. I think a hue, saturation, brightness constructor, rather than RGB, will give you exactly the effect you want. For example, often I will generate a random color with [UIColor colorWithHue:<random float in [0,1]> saturation:1.f brightness:1.f alpha:1.f].

Slide hue linearly from 0 to 1, with saturation and brightness fixed at the most legible (or whatever) values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文