tags:

views:

2128

answers:

5

How can I change the color as well as size of UIProgressBar in iPhone SDK

+2  A: 

Assuming you mean a UIProgressView, you can resize it as you would any other view, by setting the frame:

UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
[progressView setFrame:CGRectMake(0,0,320,10)];

or if you're using the default style, you can set the frame in the init method:

UIProgressView *progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0,0,320,10)];

As far as I know, the color of a UIProgressView cannot be changed. You'll probably have to roll your own view for that.

Can Berk Güder
Is there a way to make the UIPrograssView run?
MrThys
what do you mean by run? like an indeterminate NSProgressIndicator?
Can Berk Güder
A: 

As Can noted, there is very little customization available for UIProgressView... pretty sucky. The solution I just implemented was to hack a UISlider. Here's the inspiration, from Apple's support forum.

  1. Create a new UISlider
  2. Set the setMinimumTrackImage and setMaximumTrackImage to your desired UIImage values
  3. Set the setThumbImage to nil
  4. Set the upper and lower bounds of the slider

Once this is setup and added to your UIView, use your custom method to set the value of the slider to the value you would normally have assigned to the UIPRogressView's progress.

Dan Harrelson
A: 

You could probably also hack one together using an image that looks like the progress bar at it's smallest size and then create a stretchable image with it.

UIImage *progressBarImg= [someImage stretchableImageWithLeftCapWidth:5.0 topCapHeight:0.0];

Then you could set the image as the backgroundImage for a disabled UIButton and animate the button width incrementally to indicate progress. I haven't tried this, but I think it would work.

Christopher Scott
+1  A: 

For changing the color you could use this third-party UIProgressView subclass: http://p-development.nl/blog/colored-uiprogressview.

Dufu