MBProgressHUD水平进度条xamarin ios

问题描述 投票:0回答:1

我需要在水平进度条中显示加载状态。我正在使用xamarin ios中的包MBProgressHUD

我有这个方法,

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;
}

最大值为18,进度参数从1开始,此方法调用18次。当这个方法第一次调用时,进度条完全加载,这是错误的。如何根据进度值加载此进度?

谢谢

xamarin.forms xamarin.ios mbprogresshud
1个回答
2
投票

我注意到你将参数progress声明为int。事实上,你应该将它声明为float,因为进展范围是从01。例如,您可以改进代码,如下所示:

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;
    }
© www.soinside.com 2019 - 2024. All rights reserved.