2

I am having two values targetValue and receivedValue . Now I want to show the status on Progress bar. Means if targetValue is 1000 and receivedValue is 500 then progress bar should display 50% of filled area.

So I want to know that is there any easy way to do so... or I have to calculate the values any have to set with myProgressBar.progress = value ?

Maulik
  • 19,348
  • 14
  • 82
  • 137

3 Answers3

8

Use below

myProgressBar.progress = receivedValue /targetValue ;

The value of receivedValue /targetValue will fall in the range of 0.0 to 1.0 ;

Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76
2

ofcorse you have to calculate value and pass it.

myProgressBar.progress = value
Rakesh Bhatt
  • 4,606
  • 3
  • 25
  • 38
  • ok ! i thought there would be some inbuilt function to set max value for progress bar and based on current value its display filled area... thanks for reply – Maulik Apr 08 '11 at 10:02
  • just convert ur value in 0-100 by calculating percentage. that's it. – Rakesh Bhatt Apr 08 '11 at 10:08
0

Here is a solution I recommend:

-(void)UpdateProgressbar:(NSNumber*)currentOperationNumer TotalOperationNumber:(NSNumber*)n
{       
    NSLog(@" operation : %i", currentOperationNumer);
    NSLog(@" total : %i", n);       

    NSString *inStr = [NSString stringWithFormat:@"%d", n];
    NSLog(@"%@", inStr);

    NSString *Str = [NSString stringWithFormat:@"%d", currentOperationNumer];
    NSLog(@"%@", Str);
    if (currentOperationNumer <= n) {           
        [downloadBar setProgress:([Str intValue]/[inStr floatValue])];
        NSLog(@"progress !");           
    }
    else {
        [self.view removeFromSuperview];
    }    
}
Jamal
  • 763
  • 7
  • 22
  • 32
Bechir
  • 202
  • 2
  • 7