1

I have a button connected to a UiProgressView, has only the function to count the clicks on the button ... I need to show the percentage of completion in a UILabel .. Can you tell me which method is better?

To make you understand the function I show you the code of the IBAction

- (IBAction)FFAddCFU:(id)sender {
if (FFVariabileNumerica_CFU >= 30)
return;
FFVariabileNumerica_CFU++ ;
[FFCFULabel setText:[NSString stringWithFormat:@"%d", FFVariabileNumerica_CFU]];

if(FFProgressBar.progress == 0.50 || FFProgressBar.progress == 0.77 ){
[ FFProgressBar setProgress : FFProgressBar.progress +0.25 ];

} else {
if (FFProgressBar.progress > 0.76) {
[ FFProgressBar setProgress : FFProgressBar.progress +0.25 ]; }
}
}
Zach Saucier
  • 24,871
  • 12
  • 85
  • 147
kAiN
  • 2,559
  • 1
  • 26
  • 54

1 Answers1

1

I've done this in a small project of mine for a custom progress view. It can be found at lightdesign/LDProgressView. You can take a look at the file LDProgressView.m for how I've done this.

Here's the relevant line:

label.text = [NSString stringWithFormat:@"%.0f%%", self.progress*100];

This line takes the progress value which is between 0.0 and 1.0 and multiplies it by 100 and then inserts the number up to the whole number (.0 in the format string) with a percentage at the end (%% in the format string).

Also, if you don't want to manually calculate the percentage, feel free to use the open source control I've made.

Christian Di Lorenzo
  • 3,562
  • 24
  • 33
  • Hello and thank you very much for your response ... I tried everything today to understand the operation of your LDProgressView, but unfortunately I'm still a newbie: (((it was not easy to understand .. It 'a nice code: P ... I noticed the implementation of the percentage but I could not to understand how it can be implemented in a Label with NSString, I've noticed that you've implemented through the use of the control segment. Excuse me for my bad english, i'm italian – kAiN Oct 13 '13 at 01:45
  • I've updated my answer. I hope it helps you understand what I'm doing in `LDProgressView`. BTW, I also have a bit of italian blood in me, but I don't know the language at all :-). – Christian Di Lorenzo Oct 13 '13 at 02:01
  • Christian Works great! Thank you so much! .... Great Italian blood! : D Now everything works I have only problems with IBAction because if I push a button gives me 75% if they push me another 77% .. I had to do this because I wanted the progress advancing only once for every button and every time I click no matter which button ... That 'sa bit difficult because I tired the brain: D to find the right situation. When push a button and get to 75% and if I always push the same button, the progress does not advance forward but only if I push another button other ... This is what I wanted to do – kAiN Oct 13 '13 at 02:26