ProgressDialog相当于iOS

时间:2016-07-12 14:14:07

标签: ios iphone xamarin xamarin.ios

我正在使用Xamarin.iOS开始iOS的开发,我想知道在iOS中是否有Android等效的ProgressDialog?

换句话说,我想在iOS中创建一个这样的模态: enter image description here

3 个答案:

答案 0 :(得分:2)

我想,

https://components.xamarin.com/view/mbprogresshud/

是最好的选择。您可以从这里找到信息

https://components.xamarin.com/gettingstarted/mbprogresshud

编辑1

这是我写的静态类。希望能帮到你

using CoreGraphics;
using MBProgressHUD;
using System;
using System.Collections.Generic;
using System.Text;
using UIKit;
namespace CandyCaneClub.iOS.Helper
{
/*
A generic helper class to show and hide the overlay for running processes on application 
*/
    public class OverlayHelper 
    {
        public static MTMBProgressHUD overlay;
        //Initialize the Overlay with string as a message to show and view on which we suppose to show
        public static MTMBProgressHUD InitOverlay(string message, UIView view)
        {
            overlay = new MTMBProgressHUD(view)
            {
                LabelText = message,
                RemoveFromSuperViewOnHide = true
            };
            overlay.Alpha = 0.75f;
            view.AddSubview(overlay);
            overlay.Show(animated: true);
            return overlay;
        }
        //Hide the overlay 
        public static void HideOverlay()
        {
            if(overlay != null)
            overlay.Hide(animated: true, delay: 2);
        }
    }
}

答案 1 :(得分:1)

Xamarin已为此精确视图发布了完整的配方。  https://developer.xamarin.com/recipes/ios/standard_controls/popovers/display_a_loading_message/

public class LoadingOverlay : UIView {

    // control declarations
    UIActivityIndicatorView activitySpinner;
    UILabel loadingLabel;

    public LoadingOverlay (CGRect frame) : base (frame)
    {
        // configurable bits
        BackgroundColor = UIColor.Black;
        Alpha = 0.75f;
        AutoresizingMask = UIViewAutoresizing.All;

        nfloat labelHeight = 22;
        nfloat labelWidth = Frame.Width - 20;

        // derive the center x and y
        nfloat centerX = Frame.Width / 2;
        nfloat centerY = Frame.Height / 2;

        // create the activity spinner, center it horizontall and put it 5 points above center x
        activitySpinner = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.WhiteLarge);
        activitySpinner.Frame = new CGRect (
            centerX - (activitySpinner.Frame.Width / 2) ,
            centerY - activitySpinner.Frame.Height - 20 ,
            activitySpinner.Frame.Width,
            activitySpinner.Frame.Height);
        activitySpinner.AutoresizingMask = UIViewAutoresizing.All;
        AddSubview (activitySpinner);
        activitySpinner.StartAnimating ();

        // create and configure the "Loading Data" label
        loadingLabel = new UILabel(new CGRect (
            centerX - (labelWidth / 2),
            centerY + 20 ,
            labelWidth ,
            labelHeight
            ));
        loadingLabel.BackgroundColor = UIColor.Clear;
        loadingLabel.TextColor = UIColor.White;
        loadingLabel.Text = "Loading Data...";
        loadingLabel.TextAlignment = UITextAlignment.Center;
        loadingLabel.AutoresizingMask = UIViewAutoresizing.All;
        AddSubview (loadingLabel);

    }

    /// <summary>
    /// Fades out the control and then removes it from the super view
    /// </summary>
    public void Hide ()
    {
        UIView.Animate (
            0.5, // duration
            () => { Alpha = 0; },
            () => { RemoveFromSuperview(); }
        );
    }
}

enter image description here

答案 2 :(得分:0)

This Xamarin.IOS documentation link应该为您提供构建进度对话框所需的内容。在他们的例子中,进度对话框占据了整个屏幕,但是通过一些参数调整,你可以使它基本上看起来你想要它。