0

I am working on an iPhone app utilizing two UIProgressviews. The problem is that it is quite simple to show the progress of something 5/100 or 5/10 but in order to show something 5/16 I would need to change the maximum value of the progress view. I can't seem to find a (I think it's called) property of progress views that I could use with it. For example something like .maximumValue. Any help is greatly appreciated, thanks!

ZB-dev
  • 219
  • 3
  • 12
  • int MAXVALUE = 16; progressView.progress = 5/MAXVALUE; – lakshmen Jul 03 '13 at 18:11
  • 1
    @lakesh That will set `progress` to zero because you're performing integer division. – rob mayoff Jul 03 '13 at 18:12
  • @robmayoff thanks. Made a mistake as well. – lakshmen Jul 03 '13 at 18:14
  • 1
    What ist the problem here? `.property` is a `float` anyway, a sort of procentual value between 0 and 1, similar to the `.alpha` property of `UIView` or each color component value when creating an `UIColor` from rgb values. Just make sure that it is really a float and not an int caluclation. Devide by `16.0f` if it is a constant or assign it to a float or use the `floatValue` method of an `NSNumber`. (Strictly spoken `16f` or `16.0` should do, but `16.0f` is rather conventional.) – Hermann Klecker Jul 03 '13 at 18:44

3 Answers3

3

UIProgressView's progress property stands from 0 to 1.

So its require to divide as per your maximum value.

For example, if in application, there is maximum value is 23 then code should be like this:

float progressValue = <Actual Value> / 23.0;

[myProgressView setProgress: progreassValue];

Refer UIProgressView class reference for more details

Mrunal
  • 13,982
  • 6
  • 52
  • 96
3

The UIProgressView progress property varies from 0 (meaning no progress at all) to 1 (meaning everything is done).

So:

self.progressView.progress = 5.0 / 16.0;

Or, to animate to the new progress:

[self.progressView setProgress:5.0/16.0 animated:YES];

Technically, the progress property is a float, so you could say 5.0f / 16.0f to save a few nanoseconds. But you are probably not updating the property often enough for this to matter.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
1

As ProgressView progress property is of type float, you can use type casting as follows :

int value=5;
int MaxValue=15;
float Progress=(float)value/MaxValue;
[self.myProgressview setProgress:Progress animated:YES];
Mahesh
  • 526
  • 1
  • 6
  • 21