English 中文(简体)
iOS 如何计算工具栏梯度?
原标题:How does iOS calculate a toolbar gradient?

iOS 如何计算工具栏梯度? 我希望能够设置我的窗口背景颜色来匹配梯度中的结尾颜色, 以便它看起来逐渐淡入视图。 问题是, 结尾色似乎随底色而变化, 我找不到一个匹配的一致公式 。

最佳回答

我最好的近似点是:

(r , g , b ) = (f(r), f(g), f(b)) where f(x) = 0.001468x^2 + 0.647295x + 4.04025

How I derived that: Let c = (r, g, b) = base color. Let c = (r , g , b ) = resulting color. I let c = #944321 = (148, 67, 33) and got c = #84361b = (132, 54, 27).

这让我有三个方程式要解决:

f(148) = 132
f(67) = 54
f(33) = 27

既然我们有三个方程式,那么 f(x) 应该是三种未知的多元方程式:

f(x) = Ax^2 + Bx + C

从那里,我在计算器上做了一个3x4矩阵,输入了x的不同值,并在矩阵上做了一个缩排层,解决办法是 < code>(0.001468, 0.647295, 4.04025) ,我在A、B和C中插入了这些代码,并获得了上述 < code>f(x) 。

这里有一个快速的 Python 脚本来进行计算 。

用法: ./patr.py rggbb

#!/usr/bin/env python

import sys

def end_color(color):
    def f(x):
        return int(round(0.001468 * x ** 2 + 0.647295 * x + 4.04025))
    rgb = (int(color[i:i+2], 16) for i in xrange(0, 6, 2))
    return   .join(hex(f(n))[2:] for n in rgb)

for color in sys.argv[1:]:
    print end_color(color)

我用颜色

$ ./script.py 9e3393
8f2983

即使它有时不准确, 也可能无法分辨, 因为您正在使用渐变末端的颜色。 希望有帮助!

问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签