using System; 
 | 
using UIKit; 
 | 
using CoreGraphics; 
 | 
  
 | 
namespace Shared 
 | 
{ 
 | 
    /// <summary> 
 | 
    /// Loading UI 
 | 
    /// </summary> 
 | 
    public class Loading : View 
 | 
    { 
 | 
  
 | 
        public bool CurStatus = false; 
 | 
        internal IosLoading iosLoading 
 | 
        { 
 | 
            get 
 | 
            { 
 | 
                return uiView as IosLoading; 
 | 
            } 
 | 
            set 
 | 
            { 
 | 
                uiView = value; 
 | 
            } 
 | 
        } 
 | 
  
 | 
        /// <summary> 
 | 
        /// Loading UI 
 | 
        /// </summary> 
 | 
        public Loading() 
 | 
        { 
 | 
            var bounds = UIScreen.MainScreen.Bounds; 
 | 
            iosLoading = new IosLoading(bounds); 
 | 
        } 
 | 
  
 | 
  
 | 
        /// <summary> 
 | 
        /// 开始当前视图 
 | 
        /// </summary> 
 | 
        public void Start() 
 | 
        { 
 | 
            iosLoading.uiLabel.Text = "Loading......"; 
 | 
            iosLoading.Start(); 
 | 
            CurStatus = true; 
 | 
        } 
 | 
  
 | 
        /// <summary> 
 | 
        /// 开始当前视图 
 | 
        /// </summary> 
 | 
        public void Start(string s) 
 | 
        { 
 | 
            iosLoading.uiLabel.Text = s; 
 | 
            iosLoading.Start(); 
 | 
        } 
 | 
  
 | 
  
 | 
        /// <summary> 
 | 
        /// 隐藏当前视图 
 | 
        /// </summary> 
 | 
        public void Hide() 
 | 
        { 
 | 
            iosLoading.uiLabel.Text = "Loading......"; 
 | 
            iosLoading.Hide(); 
 | 
            CurStatus = false; 
 | 
        } 
 | 
  
 | 
        public string Text 
 | 
        { 
 | 
            get 
 | 
            { 
 | 
                return iosLoading.uiLabel.Text; 
 | 
            } 
 | 
            set 
 | 
            { 
 | 
                iosLoading.uiLabel.Text = value; 
 | 
            } 
 | 
        } 
 | 
  
 | 
        public virtual uint LodingBackgroundColor 
 | 
        { 
 | 
            get 
 | 
            { 
 | 
                return (iosLoading as IosLoading).LodingBackgroundColor; 
 | 
            } 
 | 
            set 
 | 
            { 
 | 
                (iosLoading as IosLoading).LodingBackgroundColor = value; 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
  
 | 
    internal class IosLoading : UIView { 
 | 
         
 | 
        UIActivityIndicatorView activitySpinner= new UIActivityIndicatorView(UIActivityIndicatorViewStyle.WhiteLarge); 
 | 
        public UILabel uiLabel=new UILabel(); 
 | 
        UIView backUIView = new UIView(new CGRect(0, 0, 160, 100)); 
 | 
  
 | 
        public IosLoading(CGRect frame) 
 | 
        { 
 | 
            Frame = frame; 
 | 
            Hidden = true; 
 | 
  
 | 
            AutoresizingMask = UIViewAutoresizing.All; 
 | 
  
 | 
            var f = backUIView.Frame; 
 | 
            f.Width = frame.Width; 
 | 
            f.Height = frame.Height; 
 | 
            backUIView.Frame = f; 
 | 
            var center = backUIView.Center; 
 | 
            center.X = Frame.Width / 2;  
 | 
            center.Y = Frame.Height / 2;  
 | 
            backUIView.Center = center; 
 | 
            AddSubview(backUIView); 
 | 
            // create the activity spinner, center it horizontall and put it 5 points above center x 
 | 
            var center1 = activitySpinner.Center; 
 | 
            center1.X = backUIView.Frame.Width / 2; 
 | 
            center1.Y = (backUIView.Frame.Height - 22) / 2; 
 | 
            activitySpinner.Center = center1; 
 | 
            backUIView.AddSubview(activitySpinner); 
 | 
            activitySpinner.BackgroundColor = UIColor.Clear; 
 | 
  
 | 
            var frame2 = uiLabel.Frame; 
 | 
            frame2.Y = activitySpinner.Frame.Bottom+22; 
 | 
            frame2.Width = backUIView.Frame.Width; 
 | 
            frame2.Height = 22; 
 | 
            uiLabel.Frame = frame2; 
 | 
  
 | 
            uiLabel.BackgroundColor = UIColor.Clear; 
 | 
            uiLabel.TextColor = UIColor.White; 
 | 
            uiLabel.TextAlignment = UITextAlignment.Center; 
 | 
            backUIView.AddSubview(uiLabel); 
 | 
        } 
 | 
  
 | 
        public void Start() 
 | 
        { 
 | 
            if (Superview == null) 
 | 
            { 
 | 
                return; 
 | 
            } 
 | 
            BackgroundColor = UIKit.UIColor.FromRGBA(0x32, 0x32, 0x32, 0xF0); 
 | 
            Hidden = false; 
 | 
            activitySpinner.StartAnimating(); 
 | 
            Superview.BringSubviewToFront(this); 
 | 
        } 
 | 
  
 | 
        /// <summary> 
 | 
        /// Fades out the control and then removes it from the super view 
 | 
        /// </summary> 
 | 
        public void Hide () 
 | 
        { 
 | 
            if(Superview==null){ 
 | 
                return; 
 | 
            } 
 | 
            Hidden = true; 
 | 
            activitySpinner.StopAnimating (); 
 | 
            Superview.SendSubviewToBack(this); 
 | 
        } 
 | 
  
 | 
        uint loadingBackgroundColor; 
 | 
        /// <summary> 
 | 
        /// 背景颜色 
 | 
        /// </summary> 
 | 
        /// <value>The color of the background.</value> 
 | 
        public virtual uint LodingBackgroundColor 
 | 
        { 
 | 
            get 
 | 
            { 
 | 
                return loadingBackgroundColor; 
 | 
            } 
 | 
            set 
 | 
            { 
 | 
                loadingBackgroundColor = value; 
 | 
  
 | 
                if (this.GetType() != typeof(ImageView)) 
 | 
                { 
 | 
                    byte r, g, b, a; 
 | 
                    r = (byte)(loadingBackgroundColor / 256 / 256 % 256); 
 | 
                    g = (byte)(loadingBackgroundColor / 256 % 256); 
 | 
                    b = (byte)(loadingBackgroundColor % 256); 
 | 
                    a = (byte)(loadingBackgroundColor / 256 / 256 / 256 % 256); 
 | 
                    backUIView.BackgroundColor = UIKit.UIColor.FromRGBA(r, g, b, a); 
 | 
  
 | 
  
 | 
                    backUIView.Layer.MasksToBounds = true; 
 | 
                    backUIView.Layer.CornerRadius = 6; 
 | 
                    backUIView.Layer.BorderWidth = 0; 
 | 
                } 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
} 
 |