MBProgressHUD 水平进度条 xamarin ios
MBProgressHUD horizontal progress bar xamarin ios
我需要在水平进度条中显示加载状态。
我在 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;
}
max值为18,progress参数从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;
}
我需要在水平进度条中显示加载状态。 我在 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;
}
max值为18,progress参数从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;
}