我需要在水平进度条中显示加载状态。我正在使用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次。当这个方法第一次调用时,进度条完全加载,这是错误的。如何根据进度值加载此进度?
谢谢
我注意到你将参数progress
声明为int
。事实上,你应该将它声明为float
,因为进展范围是从0
到1
。例如,您可以改进代码,如下所示:
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;
}