wxr
2020-06-15 b8e94316e41eba72d927d5ca7d931b26139ee8ff
Shared.IOS/UI/Loading.cs
@@ -4,76 +4,94 @@
namespace Shared
{
   /// <summary>
   /// Loading UI
   /// </summary>
   public class Loading : View
   {
    /// <summary>
    /// Loading UI
    /// </summary>
    public class Loading : View
    {
        public bool CurStatus = false;
      internal IosLoading iosLoading
      {
         get
         {
            return uiView as IosLoading;
         }
         set
         {
            uiView = value;
         }
      }
        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>
        /// 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();
        /// <summary>
        /// 开始当前视图
        /// </summary>
        public void Start()
        {
            Text = "Loading......";
            iosLoading.Start();
            CurStatus = true;
        }
      /// <summary>
      /// 开始当前视图
      /// </summary>
      public void Start(string s)
      {
         iosLoading.uiLabel.Text = s;
         iosLoading.Start();
        /// <summary>
        /// 开始当前视图
        /// </summary>
        public void Start(string s)
        {
            Text = s;
            iosLoading.Start();
        }
      /// <summary>
      /// 隐藏当前视图
      /// </summary>
      public void Hide()
      {
            iosLoading.uiLabel.Text = "Loading......";
        /// <summary>
        /// 隐藏当前视图
        /// </summary>
        public void Hide()
        {
            Text = "Loading......";
            iosLoading.Hide();
            CurStatus = false;
        }
      public string Text
      {
         get
         {
            return iosLoading.uiLabel.Text;
         }
         set
         {
            iosLoading.uiLabel.Text = value;
         }
      }
        public string Text
        {
            get
            {
                return iosLoading.uiLabel.Text;
            }
            set
            {
                iosLoading.uiLabel.Text = value;
                iosLoading.RefreshWidth();
            }
        }
        uint mTextColor;
        public uint TextColor
        {
            get
            {
                return mTextColor;
            }
            set
            {
                mTextColor = value;
                iosLoading.uiLabel.TextColor = HDLUtils.GetUIColorWithUint(mTextColor);
            }
        }
        public virtual uint LodingBackgroundColor
        {
@@ -86,16 +104,47 @@
                (iosLoading as IosLoading).LodingBackgroundColor = value;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="mViewStyle">1 为灰色</param>
        public void SetUIActivityIndicatorViewStyle(int mViewStyle)
        {
            (iosLoading as IosLoading).SetUIActivityIndicatorViewStyle(mViewStyle);
        }
        /// <summary>
        /// 文字大小
        /// </summary>
        /// <value>The size of the text.</value>
        public float TextSize
        {
            get
            {
                return (float)iosLoading.uiLabel.Font.PointSize;
            }
            set
            {
                iosLoading.uiLabel.Font = UIFont.FromName(iosLoading.uiLabel.Font.Name, 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));
    internal class IosLoading : UIView
    {
        UIActivityIndicatorView activitySpinner = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.WhiteLarge);
        public UILabel uiLabel = new UILabel();
        UIView backUIView = new UIView(new CGRect(0, 0, 160, 120));
        public IosLoading(CGRect frame)
        {
            BackgroundColor = UIKit.UIColor.FromRGBA(0x32, 0x32, 0x32, 50);
            Frame = frame;
            Hidden = true;
@@ -103,31 +152,34 @@
            var f = backUIView.Frame;
            f.Width = frame.Width;
            f.Height = frame.Height;
            //f.Height = frame.Height;
            backUIView.Frame = f;
            var center = backUIView.Center;
            center.X = Frame.Width / 2;
            center.Y = Frame.Height / 2;
            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;
            center1.Y = (backUIView.Frame.Height - 62) / 2 + 20;
            activitySpinner.Center = center1;
            backUIView.AddSubview(activitySpinner);
            activitySpinner.BackgroundColor = UIColor.Clear;
            activitySpinner.Color = UIColor.Gray;
            var frame2 = uiLabel.Frame;
            frame2.Y = activitySpinner.Frame.Bottom+22;
            frame2.Y = backUIView.Frame.Height - 42;
            frame2.Width = backUIView.Frame.Width;
            frame2.Height = 22;
            uiLabel.Frame = frame2;
            uiLabel.BackgroundColor = UIColor.Clear;
            uiLabel.TextColor = UIColor.White;
            uiLabel.TextColor = UIColor.Gray;
            uiLabel.TextAlignment = UITextAlignment.Center;
            //uiLabel.F
            backUIView.AddSubview(uiLabel);
        }
        public void Start()
@@ -136,24 +188,25 @@
            {
                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){
        /// <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);
      }
            Hidden = true;
            activitySpinner.StopAnimating();
            Superview.SendSubviewToBack(this);
        }
        uint loadingBackgroundColor;
        /// <summary>
@@ -186,6 +239,72 @@
                }
            }
        }
        public void SetUIActivityIndicatorViewStyle(int mViewStyle)
        {
            if (mViewStyle == 1)
            {
                activitySpinner.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray;
            }
            else
            {
                activitySpinner.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge;
            }
        }
        public void RefreshWidth()
        {
            int maxTextWidth = GetTextWidth() + 40;
            if (maxTextWidth > this.Frame.Width - 20)
            {
                maxTextWidth = (int)this.Frame.Width - 20;
            }
            else if (maxTextWidth < 120)
            {
                maxTextWidth = 120;
            }
            var mFrame = backUIView.Frame;
            if ((int)mFrame.Width == maxTextWidth)
            {
                return;
            }
            mFrame.Width = maxTextWidth;
            //f.Height = frame.Height;
            backUIView.Frame = mFrame;
            var center = backUIView.Center;
            center.X = Frame.Width / 2;
            center.Y = Frame.Height / 2;
            backUIView.Center = center;
            var center1 = activitySpinner.Center;
            center1.X = backUIView.Frame.Width / 2;
            activitySpinner.Center = center1;
            var frame2 = uiLabel.Frame;
            frame2.Width = backUIView.Frame.Width;
            uiLabel.Frame = frame2;
        }
        /// <summary>
        /// 获取字体长度
        /// </summary>
        int GetTextWidth()
        {
            try
            {
                CGSize fontSize = uiLabel.Text.StringSize(uiLabel.Font);
                return (int)fontSize.Width;
            }
            catch
            {
                return 0;
            }
        }
    }
}