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
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)?