diff --git a/BTProgressHUD.sln b/BTProgressHUD.sln index a2939c5..3c105f5 100644 --- a/BTProgressHUD.sln +++ b/BTProgressHUD.sln @@ -1,6 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 +# Visual Studio 2012 VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BTProgressHUD-Classic", "BTProgressHUD\BTProgressHUD-Classic.csproj", "{173ADCB0-C964-48D2-99C1-E928469F7C53}" @@ -37,6 +37,22 @@ Global {173ADCB0-C964-48D2-99C1-E928469F7C53}.Release|iPhone.Build.0 = Release|Any CPU {173ADCB0-C964-48D2-99C1-E928469F7C53}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU {173ADCB0-C964-48D2-99C1-E928469F7C53}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Ad-Hoc|iPhone.ActiveCfg = Ad-Hoc|iPhone + {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Ad-Hoc|iPhone.Build.0 = Ad-Hoc|iPhone + {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Ad-Hoc|iPhoneSimulator + {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Ad-Hoc|iPhoneSimulator.Build.0 = Ad-Hoc|iPhoneSimulator + {620134FD-4E54-4459-8E18-8B6E1C8A2274}.AppStore|iPhone.ActiveCfg = AppStore|iPhone + {620134FD-4E54-4459-8E18-8B6E1C8A2274}.AppStore|iPhone.Build.0 = AppStore|iPhone + {620134FD-4E54-4459-8E18-8B6E1C8A2274}.AppStore|iPhoneSimulator.ActiveCfg = AppStore|iPhoneSimulator + {620134FD-4E54-4459-8E18-8B6E1C8A2274}.AppStore|iPhoneSimulator.Build.0 = AppStore|iPhoneSimulator + {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Debug|iPhone.ActiveCfg = Debug|iPhone + {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Debug|iPhone.Build.0 = Debug|iPhone + {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator + {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator + {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Release|iPhone.ActiveCfg = Release|iPhone + {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Release|iPhone.Build.0 = Release|iPhone + {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator + {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator {8ECDFDC5-42D0-4540-9691-830EEB2ED874}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU {8ECDFDC5-42D0-4540-9691-830EEB2ED874}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU {8ECDFDC5-42D0-4540-9691-830EEB2ED874}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU @@ -67,27 +83,8 @@ Global {E6E84D09-BE15-460D-A317-45248BE1C56F}.Release|iPhone.Build.0 = Release|iPhone {E6E84D09-BE15-460D-A317-45248BE1C56F}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator {E6E84D09-BE15-460D-A317-45248BE1C56F}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator - {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Ad-Hoc|iPhone.ActiveCfg = Ad-Hoc|iPhone - {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Ad-Hoc|iPhone.Build.0 = Ad-Hoc|iPhone - {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Ad-Hoc|iPhoneSimulator - {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Ad-Hoc|iPhoneSimulator.Build.0 = Ad-Hoc|iPhoneSimulator - {620134FD-4E54-4459-8E18-8B6E1C8A2274}.AppStore|iPhone.ActiveCfg = AppStore|iPhone - {620134FD-4E54-4459-8E18-8B6E1C8A2274}.AppStore|iPhone.Build.0 = AppStore|iPhone - {620134FD-4E54-4459-8E18-8B6E1C8A2274}.AppStore|iPhoneSimulator.ActiveCfg = AppStore|iPhoneSimulator - {620134FD-4E54-4459-8E18-8B6E1C8A2274}.AppStore|iPhoneSimulator.Build.0 = AppStore|iPhoneSimulator - {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Debug|iPhone.ActiveCfg = Debug|iPhone - {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Debug|iPhone.Build.0 = Debug|iPhone - {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator - {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator - {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Release|iPhone.ActiveCfg = Release|iPhone - {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Release|iPhone.Build.0 = Release|iPhone - {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator - {620134FD-4E54-4459-8E18-8B6E1C8A2274}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(MonoDevelopProperties) = preSolution - StartupItem = BTProgressHUDDemo\BTProgressHUDDemo.csproj - EndGlobalSection EndGlobal diff --git a/BTProgressHUD/BTProgressHUD-Classic.csproj b/BTProgressHUD/BTProgressHUD-Classic.csproj index a9c33f2..d9a2ce4 100644 --- a/BTProgressHUD/BTProgressHUD-Classic.csproj +++ b/BTProgressHUD/BTProgressHUD-Classic.csproj @@ -3,8 +3,6 @@ Debug AnyCPU - 8.0.30703 - 2.0 {173ADCB0-C964-48D2-99C1-E928469F7C53} {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Library diff --git a/BTProgressHUD/BTProgressHUD.csproj b/BTProgressHUD/BTProgressHUD.csproj index c316ce8..305cc13 100644 --- a/BTProgressHUD/BTProgressHUD.csproj +++ b/BTProgressHUD/BTProgressHUD.csproj @@ -3,8 +3,6 @@ Debug AnyCPU - 8.0.30703 - 2.0 {8ECDFDC5-42D0-4540-9691-830EEB2ED874} {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Library diff --git a/BTProgressHUD/ProgressHUD.cs b/BTProgressHUD/ProgressHUD.cs index f290c69..eb3de98 100644 --- a/BTProgressHUD/ProgressHUD.cs +++ b/BTProgressHUD/ProgressHUD.cs @@ -26,6 +26,7 @@ + #else using MonoTouch.UIKit; using MonoTouch.Foundation; @@ -190,6 +191,8 @@ public static ProgressHUD Shared { get { + + if (sharedHUD == null) sharedHUD = new ProgressHUD(UIScreen.MainScreen.Bounds); return sharedHUD; @@ -418,7 +421,7 @@ void ShowImageWorker(UIImage image, string status, TimeSpan duration) void StartDismissTimer(TimeSpan duration) { #if __UNIFIED__ - _fadeoutTimer = NSTimer.CreateTimer(duration, timer => DismissWorker ()); + _fadeoutTimer = NSTimer.CreateTimer(duration, timer => DismissWorker()); #else _fadeoutTimer = NSTimer.CreateTimer(duration, DismissWorker); #endif @@ -431,7 +434,7 @@ void StartProgressTimer(TimeSpan duration) if (_progressTimer == null) { #if __UNIFIED__ - _progressTimer = NSTimer.CreateRepeatingTimer (duration, timer => UpdateProgress ()); + _progressTimer = NSTimer.CreateRepeatingTimer(duration, timer => UpdateProgress()); #else _progressTimer = NSTimer.CreateRepeatingTimer(duration, UpdateProgress); #endif @@ -991,15 +994,6 @@ void UpdatePosition(bool textOnly = false) nfloat stringHeightBuffer = 20f; nfloat stringAndImageHeightBuffer = 80f; - /*if (IsiOS7) - { - hudHeight += 50; - hudWidth += 50f; - stringHeightBuffer += 50f; - stringAndImageHeightBuffer += 50f; - }*/ - - CGRect labelRect = new CGRect(); string @string = StringLabel.Text; @@ -1007,12 +1001,18 @@ void UpdatePosition(bool textOnly = false) // False if it's text-only bool imageUsed = (ImageView.Image != null) || (ImageView.Hidden); if (textOnly) + { imageUsed = false; + } if (imageUsed) + { hudHeight = stringAndImageHeightBuffer + stringHeight; + } else + { hudHeight = (textOnly ? stringHeightBuffer : stringHeightBuffer + 40); + } if (!string.IsNullOrEmpty(@string)) { @@ -1020,7 +1020,9 @@ void UpdatePosition(bool textOnly = false) if (IsIOS7OrNewer) { - var stringSize = new NSString(@string).GetSizeUsingAttributes(new UIStringAttributes{ Font = StringLabel.Font }); + var stringSize = new NSString(@string).GetBoundingRect(new CGSize(200, 30 * lineCount), NSStringDrawingOptions.UsesLineFragmentOrigin, + new UIStringAttributes{ Font = StringLabel.Font }, + null); stringWidth = stringSize.Width; stringHeight = stringSize.Height; } @@ -1047,7 +1049,7 @@ void UpdatePosition(bool textOnly = false) hudWidth += 24; } else - { + { hudWidth += 24; labelRect = new CGRect(0, labelRectY, hudWidth, stringHeight); } @@ -1062,7 +1064,9 @@ void UpdatePosition(bool textOnly = false) if (IsIOS7OrNewer) { - var stringSize = new NSString(@cancelCaption).GetSizeUsingAttributes(new UIStringAttributes{ Font = StringLabel.Font }); + var stringSize = new NSString(@cancelCaption).GetBoundingRect(new CGSize(200, 300), NSStringDrawingOptions.UsesLineFragmentOrigin, + new UIStringAttributes{ Font = StringLabel.Font }, + null); stringWidth = stringSize.Width; stringHeight = stringSize.Height; } @@ -1090,14 +1094,14 @@ void UpdatePosition(bool textOnly = false) if (hudHeight > 100) { cancelRect = new CGRect(12, cancelRectY, hudWidth, stringHeight); - labelRect = new CGRect(12, labelRect.Y, hudWidth, stringHeight); + labelRect = new CGRect(12, labelRect.Y, hudWidth, labelRect.Height); hudWidth += 24; } else { hudWidth += 24; cancelRect = new CGRect(0, cancelRectY, hudWidth, stringHeight); - labelRect = new CGRect(0, labelRect.Y, hudWidth, stringHeight); + labelRect = new CGRect(0, labelRect.Y, hudWidth, labelRect.Height); } CancelHudButton.Frame = cancelRect; hudHeight += (cancelRect.Height + gap); diff --git a/samples/BTProgressHUDSample-Classic/BTProgressHUDSample-Classic/BTProgressHUDDemo-Classic.csproj b/samples/BTProgressHUDSample-Classic/BTProgressHUDSample-Classic/BTProgressHUDDemo-Classic.csproj index 8317b60..24c6393 100644 --- a/samples/BTProgressHUDSample-Classic/BTProgressHUDSample-Classic/BTProgressHUDDemo-Classic.csproj +++ b/samples/BTProgressHUDSample-Classic/BTProgressHUDSample-Classic/BTProgressHUDDemo-Classic.csproj @@ -3,8 +3,6 @@ Debug iPhoneSimulator - 8.0.30703 - 2.0 {E6E84D09-BE15-460D-A317-45248BE1C56F} {6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Exe diff --git a/samples/BTProgressHUDSample/BTProgressHUDSample/BTProgressHUDDemo.csproj b/samples/BTProgressHUDSample/BTProgressHUDSample/BTProgressHUDDemo.csproj index aaf84e6..9bf87a1 100644 --- a/samples/BTProgressHUDSample/BTProgressHUDSample/BTProgressHUDDemo.csproj +++ b/samples/BTProgressHUDSample/BTProgressHUDSample/BTProgressHUDDemo.csproj @@ -3,8 +3,6 @@ Debug iPhoneSimulator - 8.0.30703 - 2.0 {620134FD-4E54-4459-8E18-8B6E1C8A2274} {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Exe diff --git a/samples/BTProgressHUDSample/BTProgressHUDSample/MainView.cs b/samples/BTProgressHUDSample/BTProgressHUDSample/MainView.cs index c67058d..31dcda9 100644 --- a/samples/BTProgressHUDSample/BTProgressHUDSample/MainView.cs +++ b/samples/BTProgressHUDSample/BTProgressHUDSample/MainView.cs @@ -16,62 +16,78 @@ namespace BTProgressHUDDemo { public class MainViewController : UIViewController { - public MainViewController () + public MainViewController() { } + UITextView text; float progress = -1; NSTimer timer; - public override void LoadView () + + public override void LoadView() { - base.LoadView (); + base.LoadView(); View.BackgroundColor = UIColor.LightGray; - MakeButton ("Show", () => { - BTProgressHUD.Show (); - KillAfter (); + MakeButton("Show", () => + { + BTProgressHUD.Show(); + KillAfter(); }); - MakeButton ("Show Message", () => { - BTProgressHUD.Show ("Processing your image", -1, ProgressHUD.MaskType.Black); - KillAfter (); + MakeButton("Cancel problem", () => + BTProgressHUD.Show("Cancel", () => KillAfter(), "This is a multilinetext\nSome more text\n more text\n and again more text") + ); + + MakeButton("Show Message", () => + { + BTProgressHUD.Show("Processing your image", -1, ProgressHUD.MaskType.Black); + KillAfter(); }); - MakeButton ("Show Success", () => { - BTProgressHUD.ShowSuccessWithStatus("Great success!") ; + MakeButton("Show Success", () => + { + BTProgressHUD.ShowSuccessWithStatus("Great success!"); }); - MakeButton ("Show Fail", () => { - BTProgressHUD.ShowErrorWithStatus("Oh, thats bad") ; + MakeButton("Show Fail", () => + { + BTProgressHUD.ShowErrorWithStatus("Oh, thats bad"); }); - MakeButton ("Toast", () => { - BTProgressHUD.ShowToast("Hello from the toast", showToastCentered: false, timeoutMs:1000) ; + MakeButton("Toast", () => + { + BTProgressHUD.ShowToast("Hello from the toast", showToastCentered: false, timeoutMs: 1000); }); - MakeButton ("Dismiss", () => { - BTProgressHUD.Dismiss (); + MakeButton("Dismiss", () => + { + BTProgressHUD.Dismiss(); }); - MakeButton ("Progress", () => { + MakeButton("Progress", () => + { progress = 0; BTProgressHUD.Show("Hello!", progress); - if (timer != null) + if (timer != null) { timer.Invalidate(); } - timer = NSTimer.CreateRepeatingTimer(0.5f, delegate { + timer = NSTimer.CreateRepeatingTimer(0.5f, delegate + { progress += 0.1f; if (progress > 1) { timer.Invalidate(); timer = null; BTProgressHUD.Dismiss(); - } else { - BTProgressHUD.Show ("Hello!", progress); + } + else + { + BTProgressHUD.Show("Hello!", progress); } @@ -79,50 +95,55 @@ public override void LoadView () NSRunLoop.Current.AddTimer(timer, NSRunLoopMode.Common); }); - MakeButton ("Dismiss", () => { - BTProgressHUD.Dismiss (); + MakeButton("Dismiss", () => + { + BTProgressHUD.Dismiss(); }); } - void KillAfter (float timeout = 1) + void KillAfter(float timeout = 1) { - if (timer != null) + if (timer != null) { timer.Invalidate(); } - timer = NSTimer.CreateRepeatingTimer(timeout, delegate { + timer = NSTimer.CreateRepeatingTimer(timeout, delegate + { BTProgressHUD.Dismiss(); }); NSRunLoop.Current.AddTimer(timer, NSRunLoopMode.Common); } + float y = 20; + void MakeButton(string text, Action del) { float x = 20; - var button = new UIButton (UIButtonType.RoundedRect); - button.Frame = new RectangleF (x, y, 280, 40); - button.SetTitle (text, UIControlState.Normal); - button.TouchUpInside += (o,e) => { - del() ; + var button = new UIButton(UIButtonType.RoundedRect); + button.Frame = new RectangleF(x, y, 280, 40); + button.SetTitle(text, UIControlState.Normal); + button.TouchUpInside += (o, e) => + { + del(); }; - View.Add (button); + View.Add(button); y += 45; } - public override void ViewDidLoad () + public override void ViewDidLoad() { - base.ViewDidLoad (); + base.ViewDidLoad(); } - public override void ViewDidAppear (bool animated) + public override void ViewDidAppear(bool animated) { - base.ViewDidAppear (animated); + base.ViewDidAppear(animated); } }