Search code examples
iosuicolor

How to get a green to show up like the charging battery on the iPhone lock screen?


I am trying to get a color to show up on screen just like the charging battery (shown here):Charging Battery

After looking at the Apple Documentation on UIColor here, I have attempted using both colorWithHue:saturation:brightness:aplha: and colorWithRed:green:blue:alpha: to get a color to show up like that.

For example when I use colorWithHue:.3 saturation:.84 brightness:1 alpha:.5 on a black background, it renders a color like this:

myGreen with colorWithHue:saturation:brightness:alpha:

or the colorWithRed:0 green:1 blue:0 alpha:.5 on a black background shows up like this:

myGreen with colorWithRed:green:blue:alpha:

It doesn't have that translucent or glossy look to it.

Is there a better method to use? Or do I just not have the values right? (I have tried many combinations)


Solution

  • UIColor represents only one colour with an opacity value (if you've stated one). In your case you might want to either use images, or override the drawRect method in a custom UIView class (Core Graphics). Take a look here for a brief introduction to the latter.