MBProgressHUD horizontal progress bar xamarin ios

385 Views Asked by At

I need to show the status of loading in horizontal progress bar. I am using the package MBProgressHUD in xamarin ios

I have this method,

public void ShowProgressBar(string title, string message, int max, int 
progress)
{
UIViewController controller = 
UIApplication.SharedApplication.KeyWindow.RootViewController;
hud = new MTMBProgressHUD(controller.View);
controller.View.AddSubview(hud);
hud.Color = UIColor.Clear.FromHex(0x8BC34A);
hud.Mode = MBProgressHUDMode.DeterminateHorizontalBar;
hud.Progress = progress;
}

max value is 18, and progress parameter starts from 1 and this method calls 18 times. when this method first call'd, progress bar fully loads, which is wrong. How to load this progress based on the progress value?

Thanks

1

There are 1 best solutions below

1
Lucas Zhang On BEST ANSWER

I noticed that you declared the parameters progress as int .In fact ,you should declare it as float , because the range of progress is from 0 to1. For example ,you can improve your code as following:

public void ShowProgressBar(string title, string message, int max, int time) //time means the number of you call this method .from 1-18
    {
        UIViewController controller =
        UIApplication.SharedApplication.KeyWindow.RootViewController;
        hud = new MTMBProgressHUD(controller.View);
        controller.View.AddSubview(hud);
        hud.Color = UIColor.Clear.FromHex(0x8BC34A);
        hud.Mode = MBProgressHUDMode.DeterminateHorizontalBar;

        float progress = time / 18.0f;

        hud.Progress = progress;
    }