wxr
2020-03-05 0bdc0a135dbe31761b53f432ed34f347f0a4e36b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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;
                }
            }
        }
    }
}