如何复制UINavigationBar的渐变颜色? [英] How can I replicate UINavigationBar's gradient colors?

查看:155
本文介绍了如何复制UINavigationBar的渐变颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试从 UINavigationBar 中复制渐变以用作自定义 UIButton 子类对象上的渐变



但是,我不知道如何导出颜色。也就是说,你只需要指定一种颜色来设置 UINavigationBar 的背景颜色 - tintColor 渐变与它似乎至少4种颜色?



我真的只对内部顶部和底部颜色感兴趣,只是在围绕酒吧的1px边框内部...外部边框颜色



进一步的研究表明,



上还有一个方便的方法, UIColor 以获得HSB值,这应该是有帮助的:

  getHue:saturation:brightness:alpha :

很有用的参考资料



HSL和HSV维基



UIColor类参考



以编程方式减轻颜色



交互式计算机图形基础知识



EDIT - 2 b
$ b

如果你不知道你可以在 UIButton 上以编程方式设置背景的渐变,这里有一些参考, :



FUN with UIBUTTONS AND CORE ANIMATION LAYERS



创建时尚UIButtons的五个提示(提供此链接的用户名为@cdo)



strong> EDIT - 3



我已经在HSB中放置了原始和内部渐变颜色值 UINavigationBar 及其相应的后退按钮(标题不相关,并始终显示为白色)。



链接到Google文档,其中包含我为几种示例颜色收集的信息:



https://docs.google.com/spreadsheet/ccc?key=0AnKVtzkNS9scdGVRN01pa1NQcC1hdThNbEVzQU8wRlE&usparing



注意:这些值是通过使用视网膜,3.5iPhone模拟器(Xcode版本4.6)iOS 6.1和使用PhotoShop的眼睛眩晕的HSB值保存屏幕截图。



BOUNTY AWARD CRITERIA



我已经为这个问题开了一笔奖金,得到一个很好的答案。我正在寻找的答案:



提供一种计算/近似(在大多数情况下)内顶和内顶的RGB或HSB值的方法,在 UINavigationBar 上设置 tintColor 后创建的内底 b

如果您还提供了一种计算后顶按钮上的内顶和内底渐变颜色的方法,则奖励积分奖励bar,但我发现这些颜色通常看起来有点黑暗)?

解决方案

渐变



长答案:应用色调颜色后,在其顶部呈现一个透明的覆盖图像。



它被称为:UITintedTopBarHighlight@2x.png它在UIKit艺术品。 (在此上传: http://cl.ly/image/2c2V3t1D1T3L



它是2x88像素的图像,必须在着色背景上水平重复。



对于后退按钮,它非常相似,但也有一个面具给它它的形状。 UItintedBackButtonHighlight和UITintedBackButtonMask。


I've been trying to replicate the gradient from UINavigationBar to use as a gradient on custom UIButton subclass objects on the same view.

However, I can't figure out how the colors are derived? That is, you only specify one color to set a UINavigationBar's background color- tintColor - but it creates a nice gradient with it seems at least 4 colors?

I'm really just interested in the "inner" top and bottom colors though - just inside the 1px border around the bar... the outer "border" colors do indeed appear different though.

EDIT - 1

Upon further research, it appears the HSB (instead of the RBG as first thought) values are being manipulated to get these different colors.

There is also a convenience method on UIColor to get the HSB values, which should be helpful:

getHue:saturation:brightness:alpha:

Helpful References Found So Far

HSL and HSV Wiki

UIColor Class Reference

Programmatically Lighten a Color

From the book Fundamentals of Interactive Computer Graphics

EDIT - 2

In case you were unaware that you could set a gradient for a background on a UIButton programmatically, here's some references for how to do such:

FUN WITH UIBUTTONS AND CORE ANIMATION LAYERS

Five Tips for Creating Stylish UIButtons (kudos to @cdo for providing this link)

EDIT - 3

I've put together a spreadsheet showing the original and the "inner" gradient colors (disregarding the outer most colors) in HSB values on UINavigationBar and its corresponding "back" button (titles are irrelevant and always displayed white).

Here's a link to the Google doc with the information that I've collected for a few sample colors:

https://docs.google.com/spreadsheet/ccc?key=0AnKVtzkNS9scdGVRN01pa1NQcC1hdThNbEVzQU8wRlE&usp=sharing

Note: these values were found by saving a screenshot using the retina, 3.5" iPhone Simulator (Xcode version 4.6) for iOS 6.1 and eye-dropping the HSB values using PhotoShop.

BOUNTY AWARD CRITERIA

I've opened a bounty on this question to bring more exposure to it and hopefully get a good answer. The answer that I'm looking for:

Provide a method of calculating/closely approximating (in most cases) the RGB or HSB values of the "inner top" and "inner bottom" gradient colors (see spreadsheet) created after setting a tintColor on UINavigationBar.

Bonus points awarded (above initial bounty offering) if you also provide a method for calculating the "inner top" and "inner bottom" gradient colors on the "back" button (which is similar to the navigation bar, but I've found these colors appear to be slightly "darker" usually)?

解决方案

Short Answer: it is not gradient

Long Answer: After tint color applied, there is a transparent overlay image rendered on top of it.

It is called: UITintedTopBarHighlight@2x.png an it is in UIKit artwork. (uploaded here: http://cl.ly/image/2c2V3t1D1T3L)

It is 2x88 pixel image, and must be repeated horizontally over tinted background.

For back button, it is very similar, but there is also a mask to give it it's shape. UItintedBackButtonHighlight and UITintedBackButtonMask.

这篇关于如何复制UINavigationBar的渐变颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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