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 ]; }
}
}
有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top