Colored UIProgressView

01-04-2009 03:43:36

A little while ago, I found myself in the position of needing a UIProgressView in a color different then the default blue. I was suprised to find out that the UIProgressView class does not support setting a tintcolor.
So I decided to subclass UIProgressView and draw my own ProgressView with support for setting a tintcolor.


The result became 'PDColoredProgressView'.









Implementing the PDColoredProgressView is as easy as:
  1. progressView = [[PDColoredProgressView alloc] initWithProgressViewStyle: UIProgressViewStyleDefault];
  2. [progressView setTintColor: [UIColor redColor]]; //or any other color you like
  3. [self.view addSubview: progressView];


PDColoredProgressView is free for anyone to use, both commerically and non-commerically, and available for download on the right. A demo app and some documentation are included.

However, if you'd decide to use it in one of your projects, a thank-you in the comments here and/or a linkback to my website from your app's about screen or support page would be greatly appreciated.


If you like this subclass and intent to use it in your software, please consider a donation. Thanks.


Comments:



schmapdy 03-13-2009 03:25:03
Thank you for posting this! Just what I was looking for. Good karma to you...

GOOBER 04-07-2009 11:46:43
Very nice. thank you for this. Works like a champ!

mfu 04-07-2009 21:06:44
Work like charm!

Thank you for sharing.

James Bull 05-06-2009 09:01:53
Any news on the iPhone torrent app? iGear sounds promising! j.bull@me.com

mushfique 05-08-2009 10:39:07
thank you so much for sharing with it. anyway did you ever happen to have tried to customize the toolbar or navigation bar by giving a background image beside using the defaults(UIBarStyleBlackOpaque or UIBarStyleBlackTranslucent)???

slavik 05-23-2009 00:51:16
many thanks!
Is any way to make it vertical?

P-development 05-24-2009 17:59:24
@slavik:
You can make it vertical by setting the transform property like this:

progressView.transform = CGAffineTransformMakeRotation(M_PI / 2);

This applies to all UIView subclasses, not just this one.

mcp 05-25-2009 03:17:29
Hey, thanks the CGAffineTransform tip really made my day!

CJ 10-20-2009 14:10:11
Great work. Thank you so much,

Dustin Bachrach 10-29-2009 21:58:55
Thanks. Was looking for this, and you saved me a bunch of time subclassing.

Supernico 11-06-2009 15:04:25
Thank you so much for this, this is exactly what I was looking for :)

KH 12-06-2009 22:49:55
Nice code!

Hopefully Apple will add such a method in future updates of the SDK, seems like a silly thing for UIProgressView not to support!

Mike 12-09-2009 16:26:24
Thanks for this. One quibble is that the addRoundedRectToPath in drawing.m looks like it came directly from apple's rects.c. Probably should cite that.

atrane 12-18-2009 09:30:27
You save a lot of effort of all of us, great code and Thanks!

Hilton 01-04-2010 18:41:59
Awesome! Looks great and works well :)

iSkythe 01-05-2010 06:18:38
Thank you this is just what I nedded! :)

iSkythe 01-05-2010 06:19:10
Ugh used to iPhone's auto-correct. Meant to say needed on nedded :P

Chris 01-07-2010 15:24:37
Thank you sooo much! This is exactly what I needed, and I had no trouble implementing it. You just saved me hours of frustration. Thanks again!

kalharri 01-11-2010 21:44:42
Thanks very much! This is just what I was about to write myself. I'll also invoke the karma gods in your name.

jz 01-20-2010 01:37:46
thanks for this, very handy!

Speed007 01-22-2010 17:05:32
Thanks

Gangadhar 02-02-2010 09:42:14
Thanks for the information.

P-development 02-10-2010 11:55:25
@Mike: You're right, addRoundedRectToPath comes from Apple's rects.c. I've now included it's original license notice. Thanks for the heads up.

To everyone: thanks for your replies. It's nice to see it's useful to you.

Neha 02-23-2010 17:10:30
Wow! Thank you so much!

bmasters 04-07-2010 21:05:39
Seems like a very useful component but in trying it out I found that changing the color didn't force a refresh if the value didn't also change. Adding setNeedsDisplay to setTintColor would seem to address that. Looking good otherwise! Thanks!!

o.lee 05-10-2010 13:21:16
thanks:)

Nivek 05-19-2010 19:41:32
Thanks! Works great.

Anthony 06-20-2010 03:05:18
Thanks a lot~ It's very useful! Also the tip of rotation transform. Is there a way to change the height of UIProgressView as well?

Joel 06-20-2010 17:13:55
Fantastic! I was looking around for this (didn't really need it but to fit my UI better) but couldn't find it in Apple's API. Good work!

P-development 06-20-2010 21:04:06
@Anthony:
Not off an UIProgressView. Off PDColoredProgressView you can by just changing the height member of the frame property.

Dimi 07-02-2010 11:11:51
Hi! That's cool.
Do u know how to make just plain ProgressView. I mean I don't need 3D.

Thanks a lots for in advance!

P-development 07-02-2010 12:40:27
Do you mean without the reflections and stuff? You can remove the reflections by commenting out/removing lines 69-80 and 107-112 in PDColoredProgressView.m

adam 07-26-2010 10:27:54
Thanks alot! Great helpful!


Leave a comment

Name: *


Comment: *