From 472fbd72ffe98695afab9760ddd298dd1d73f0ab Mon Sep 17 00:00:00 2001 From: Tomasz Cielecki Date: Mon, 13 May 2024 14:06:06 +0200 Subject: [PATCH 1/7] Allow customization of ProgressHUD through ProgressHUDAppearance --- BTProgressHUD/BTProgressHUD.cs | 3 -- BTProgressHUD/ProgressHUD.cs | 49 +++++++++----------------- BTProgressHUD/ProgressHUDAppearance.cs | 43 ++++++++++++++++++++++ BTProgressHUDDemo/MauiProgram.cs | 9 +++-- 4 files changed, 66 insertions(+), 38 deletions(-) create mode 100644 BTProgressHUD/ProgressHUDAppearance.cs diff --git a/BTProgressHUD/BTProgressHUD.cs b/BTProgressHUD/BTProgressHUD.cs index 0b14438..6e921a0 100644 --- a/BTProgressHUD/BTProgressHUD.cs +++ b/BTProgressHUD/BTProgressHUD.cs @@ -69,9 +69,6 @@ public static void Dismiss() public static bool IsVisible => ProgressHUD.ForDefaultWindow()?.IsVisible ?? false; - - - public static void Show(UIWindow forWindow, string? status = null, float progress = -1, MaskType maskType = MaskType.None) { ProgressHUD.For(forWindow)?.Show(status, progress, maskType); diff --git a/BTProgressHUD/ProgressHUD.cs b/BTProgressHUD/ProgressHUD.cs index 3209736..68c71a0 100644 --- a/BTProgressHUD/ProgressHUD.cs +++ b/BTProgressHUD/ProgressHUD.cs @@ -34,15 +34,15 @@ public sealed class ProgressHUD : UIView private static readonly NSObject obj = new(); - private UIImage? _errorImage; - private UIImage? _successImage; - private UIImage? _infoImage; - private UIImage? _errorOutlineImage; - private UIImage? _successOutlineImage; - private UIImage? _infoOutlineImage; - private UIImage? _errorOutlineFullImage; - private UIImage? _successOutlineFullImage; - private UIImage? _infoOutlineFullImage; + private UIImage? _errorImage = ProgressHUDAppearance.ErrorImage; + private UIImage? _successImage = ProgressHUDAppearance.SuccessImage; + private UIImage? _infoImage = ProgressHUDAppearance.InfoImage; + private UIImage? _errorOutlineImage = ProgressHUDAppearance.ErrorOutlineImage; + private UIImage? _successOutlineImage = ProgressHUDAppearance.SuccessOutlineImage; + private UIImage? _infoOutlineImage = ProgressHUDAppearance.InfoOutlineImage; + private UIImage? _errorOutlineFullImage = ProgressHUDAppearance.ErrorOutlineFullImage; + private UIImage? _successOutlineFullImage = ProgressHUDAppearance.SuccessOutlineFullImage; + private UIImage? _infoOutlineFullImage = ProgressHUDAppearance.InfoOutlineFullImage; private MaskType _maskType; private NSTimer? _fadeoutTimer; @@ -100,20 +100,17 @@ public ProgressHUD(UIWindow window) : base(window.Bounds) BackgroundColor = UIColor.Clear; Alpha = 0; AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight; - - SetOSSpecificLookAndFeel(); } public UIWindow HudWindow { get; private set; } public static CGRect KeyboardSize { get; private set; } = CGRect.Empty; - public UIColor HudBackgroundColour { get; set; } = UIColor.FromWhiteAlpha(0.0f, 0.8f); - public UIColor HudForegroundColor { get; set; } = UIColor.White; - public UIColor HudStatusShadowColor { get; set; } = UIColor.Black; - public UIColor HudToastBackgroundColor { get; set; } = UIColor.Clear; - public UIFont HudFont { get; set; } = UIFont.BoldSystemFontOfSize(16f); - public UITextAlignment HudTextAlignment { get; set; } = UITextAlignment.Center; + public UIColor HudBackgroundColour { get; set; } = ProgressHUDAppearance.HudBackgroundColour; + public UIColor HudForegroundColor { get; set; } = ProgressHUDAppearance.HudForegroundColor; + public UIColor HudToastBackgroundColor { get; set; } = ProgressHUDAppearance.HudToastBackgroundColor; + public UIFont HudFont { get; set; } = ProgressHUDAppearance.HudFont; + public UITextAlignment HudTextAlignment { get; set; } = ProgressHUDAppearance.HudTextAlignment; public Ring Ring { get; } = new(); public UIImage ErrorImage @@ -216,8 +213,8 @@ public UIImage InfoOutlineFullImage return For(window); } - public float RingRadius { get; set; } = 14f; - public float RingThickness { get; set; } = 6f; + public float RingRadius { get; set; } = ProgressHUDAppearance.RingRadius; + public float RingThickness { get; set; } = ProgressHUDAppearance.RingThickness; CAShapeLayer RingLayer { @@ -379,20 +376,6 @@ UIActivityIndicatorView SpinnerView } } - private void SetOSSpecificLookAndFeel() - { - HudBackgroundColour = - (System.OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13)) - ? UIColor.SystemBackground.ColorWithAlpha(0.8f) : UIColor.White.ColorWithAlpha(0.8f); - HudForegroundColor = - (System.OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13)) - ? UIColor.Label.ColorWithAlpha(0.8f) : UIColor.FromWhiteAlpha(0.0f, 0.8f); - HudStatusShadowColor = - (System.OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13)) - ? UIColor.Label.ColorWithAlpha(0.8f) : UIColor.FromWhiteAlpha(200f / 255f, 0.8f); - RingThickness = 1f; - } - public void Show(string? status = null, float progress = -1, MaskType maskType = MaskType.None, double timeoutMs = 1000) { obj.InvokeOnMainThread(() => ShowProgressWorker(progress, status, maskType, timeoutMs: timeoutMs)); diff --git a/BTProgressHUD/ProgressHUDAppearance.cs b/BTProgressHUD/ProgressHUDAppearance.cs new file mode 100644 index 0000000..e4fdda8 --- /dev/null +++ b/BTProgressHUD/ProgressHUDAppearance.cs @@ -0,0 +1,43 @@ +using System; +using UIKit; + +namespace BigTed; + +public static class ProgressHUDAppearance +{ + public static UIColor DefaultHudBackgroundColour { get; } = + OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13) ? + UIColor.SystemBackground.ColorWithAlpha(0.8f) : + UIColor.White.ColorWithAlpha(0.8f); + + public static UIColor DefaultHudForegroundColor { get; } = + OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13) ? + UIColor.Label.ColorWithAlpha(0.8f) : + UIColor.FromWhiteAlpha(0.0f, 0.8f); + + public static UIColor DefaultHudToastBackgroundColor { get; } = UIColor.Clear; + public static UIFont DefaultHudFont { get; } = UIFont.BoldSystemFontOfSize(16f); + public static UITextAlignment DefaultHudTextAlignment { get; } = UITextAlignment.Center; + public const float DefaultRingRadius = 14f; + public const float DefaultRingThickness = 1f; + + public static float RingRadius { get; set; } = DefaultRingRadius; + public static float RingThickness { get; set; } = DefaultRingThickness; + + + public static UIColor HudBackgroundColour { get; set; } = DefaultHudBackgroundColour; + public static UIColor HudForegroundColor { get; set; } = DefaultHudForegroundColor; + public static UIColor HudToastBackgroundColor { get; set; } = DefaultHudToastBackgroundColor; + public static UIFont HudFont { get; set; } = DefaultHudFont; + public static UITextAlignment HudTextAlignment { get; set; } = DefaultHudTextAlignment; + + public static UIImage? ErrorImage { get; set; } + public static UIImage? SuccessImage { get; set; } + public static UIImage? InfoImage { get; set; } + public static UIImage? ErrorOutlineImage { get; set; } + public static UIImage? SuccessOutlineImage { get; set; } + public static UIImage? InfoOutlineImage { get; set; } + public static UIImage? ErrorOutlineFullImage { get; set; } + public static UIImage? SuccessOutlineFullImage { get; set; } + public static UIImage? InfoOutlineFullImage { get; set; } +} diff --git a/BTProgressHUDDemo/MauiProgram.cs b/BTProgressHUDDemo/MauiProgram.cs index 5bea1e3..b893b9e 100644 --- a/BTProgressHUDDemo/MauiProgram.cs +++ b/BTProgressHUDDemo/MauiProgram.cs @@ -1,4 +1,7 @@ -namespace BTProgressHUDDemo2; +using BigTed; +using UIKit; + +namespace BTProgressHUDDemo2; public static class MauiProgram { @@ -14,7 +17,9 @@ public static MauiApp CreateMauiApp() }); #if IOS || MACCATALYST - BigTed.ProgressHUD.Initialize(); + ProgressHUD.Initialize(); + ProgressHUDAppearance.HudFont = UIFont.PreferredHeadline; + ProgressHUDAppearance.HudForegroundColor = UIColor.Purple; #endif return builder.Build(); From 10820dc05493e54662c80a52d1b7085ccacce7cf Mon Sep 17 00:00:00 2001 From: Tomasz Cielecki Date: Mon, 13 May 2024 14:12:05 +0200 Subject: [PATCH 2/7] Update readme --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 218f3df..f138564 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,20 @@ BTProgressHUD.ShowImage(UIImage.FromFile(…), "Nice one Stu!"); You can use the timeout parameter of ShowImage to control the time before it's dismissed. +## Customization +You can customize the appearance of the ProgressHUD through the `ProgressHUDAppearance` class where you can controll the +following options: + +- Background Color +- Foreground Color +- Font +- TextAlignment +- Ring Radius +- Ring Thickness +- Images and the various outlined/full versions for: + - Error + - Success + - Info ## Credits From 96773069e14a20384fe826c570689f04b8d51e88 Mon Sep 17 00:00:00 2001 From: Tomasz Cielecki Date: Mon, 13 May 2024 21:08:23 +0200 Subject: [PATCH 3/7] Split some styles and make them resettable --- BTProgressHUD/ProgressHUD.cs | 52 +++++-------- BTProgressHUD/ProgressHUDAppearance.cs | 103 ++++++++++++++++++++++++- BTProgressHUD/Ring.cs | 36 --------- BTProgressHUDDemo/MainViewModel.cs | 41 ++++++---- BTProgressHUDDemo/MauiProgram.cs | 2 - 5 files changed, 146 insertions(+), 88 deletions(-) delete mode 100644 BTProgressHUD/Ring.cs diff --git a/BTProgressHUD/ProgressHUD.cs b/BTProgressHUD/ProgressHUD.cs index 68c71a0..0888706 100644 --- a/BTProgressHUD/ProgressHUD.cs +++ b/BTProgressHUD/ProgressHUD.cs @@ -106,13 +106,6 @@ public ProgressHUD(UIWindow window) : base(window.Bounds) public static CGRect KeyboardSize { get; private set; } = CGRect.Empty; - public UIColor HudBackgroundColour { get; set; } = ProgressHUDAppearance.HudBackgroundColour; - public UIColor HudForegroundColor { get; set; } = ProgressHUDAppearance.HudForegroundColor; - public UIColor HudToastBackgroundColor { get; set; } = ProgressHUDAppearance.HudToastBackgroundColor; - public UIFont HudFont { get; set; } = ProgressHUDAppearance.HudFont; - public UITextAlignment HudTextAlignment { get; set; } = ProgressHUDAppearance.HudTextAlignment; - public Ring Ring { get; } = new(); - public UIImage ErrorImage { get => _errorImage ?? ImageHelper.ErrorImage.Value!; @@ -212,9 +205,6 @@ public UIImage InfoOutlineFullImage return For(window); } - - public float RingRadius { get; set; } = ProgressHUDAppearance.RingRadius; - public float RingThickness { get; set; } = ProgressHUDAppearance.RingThickness; CAShapeLayer RingLayer { @@ -223,7 +213,8 @@ CAShapeLayer RingLayer if (_ringLayer == null) { var center = new CGPoint(HudView.Frame.Width / 2, HudView.Frame.Height / 2); - _ringLayer = ShapeHelper.CreateRingLayer(center, RingRadius, RingThickness, Ring.Color); + _ringLayer = ShapeHelper.CreateRingLayer(center, ProgressHUDAppearance.RingRadius, + ProgressHUDAppearance.RingThickness, ProgressHUDAppearance.RingColor); HudView.Layer.AddSublayer(_ringLayer); } return _ringLayer; @@ -237,7 +228,8 @@ CAShapeLayer RingLayer if (_backgroundRingLayer == null) { var center = new CGPoint(HudView.Frame.Width / 2, HudView.Frame.Height / 2); - _backgroundRingLayer = ShapeHelper.CreateRingLayer(center, RingRadius, RingThickness, Ring.BackgroundColor); + _backgroundRingLayer = ShapeHelper.CreateRingLayer(center, ProgressHUDAppearance.RingRadius, + ProgressHUDAppearance.RingThickness, ProgressHUDAppearance.RingBackgroundColor); _backgroundRingLayer.StrokeEnd = 1; HudView.Layer.AddSublayer(_backgroundRingLayer); } @@ -266,13 +258,13 @@ UIView HudView var hudView = new UIToolbar { Translucent = true, - BarTintColor = HudBackgroundColour, - BackgroundColor = HudBackgroundColour, + BarTintColor = ProgressHUDAppearance.HudBackgroundColor, + BackgroundColor = ProgressHUDAppearance.HudBackgroundColor, AutoresizingMask = UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleTopMargin | UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleLeftMargin }; - hudView.Layer.CornerRadius = 10; + hudView.Layer.CornerRadius = ProgressHUDAppearance.HudCornerRadius; hudView.Layer.MasksToBounds = true; AddSubview(hudView); @@ -289,12 +281,12 @@ UILabel StringLabel { _stringLabel ??= new UILabel { - BackgroundColor = HudToastBackgroundColor, + BackgroundColor = ProgressHUDAppearance.HudToastBackgroundColor, AdjustsFontSizeToFitWidth = true, - TextAlignment = HudTextAlignment, + TextAlignment = ProgressHUDAppearance.HudTextAlignment, BaselineAdjustment = UIBaselineAdjustment.AlignCenters, - TextColor = HudForegroundColor, - Font = HudFont, + TextColor = ProgressHUDAppearance.HudTextColor, + Font = ProgressHUDAppearance.HudFont, Lines = 0 }; @@ -318,9 +310,8 @@ UIButton CancelHudButton BackgroundColor = UIColor.Clear, UserInteractionEnabled = true }; - _cancelHud.TitleLabel.Font = HudFont; - - _cancelHud.SetTitleColor(HudForegroundColor, UIControlState.Normal); + _cancelHud.TitleLabel.Font = ProgressHUDAppearance.HudButtonFont; + _cancelHud.SetTitleColor(ProgressHUDAppearance.HudButtonTextColor, UIControlState.Normal); UserInteractionEnabled = true; } @@ -361,11 +352,14 @@ UIActivityIndicatorView SpinnerView { get { - _spinnerView ??= new UIActivityIndicatorView(UIActivityIndicatorViewStyle.WhiteLarge) + _spinnerView ??= new UIActivityIndicatorView( + OperatingSystem.IsMacCatalystVersionAtLeast(13, 1) || OperatingSystem.IsIOSVersionAtLeast(13) ? + UIActivityIndicatorViewStyle.Large : + UIActivityIndicatorViewStyle.WhiteLarge) { HidesWhenStopped = true, Bounds = new CGRect(0, 0, 37, 37), - Color = HudForegroundColor + Color = ProgressHUDAppearance.RingColor }; // ReSharper disable once ConditionIsAlwaysTrueOrFalse @@ -493,9 +487,6 @@ private void ShowProgressWorker( ToastPosition toastPosition = ToastPosition.Center, string? cancelCaption = null, Action? cancelCallback = null, double timeoutMs = 1000, bool showContinuousProgress = false, UIImage? displayContinuousImage = null) { - if (TintColor != null) - Ring.ResetStyle(TintColor); - // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (OverlayView.Superview == null) { @@ -540,7 +531,7 @@ private void ShowProgressWorker( } RingLayer.StrokeEnd = 0.0f; - StartProgressTimer(TimeSpan.FromMilliseconds(Ring.ProgressUpdateInterval)); + StartProgressTimer(TimeSpan.FromMilliseconds(ProgressHUDAppearance.RingProgressUpdateInterval)); } else { @@ -634,7 +625,7 @@ private void ShowImageWorker(UIImage image, string? status, MaskType maskType, T Show(null, -1F, maskType); } - ImageView.TintColor = HudForegroundColor; + ImageView.TintColor = ProgressHUDAppearance.HudForegroundColor; ImageView.Image = image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); ImageView.Hidden = false; StringLabel.Text = status; @@ -745,9 +736,6 @@ private void RemoveHud() UnRegisterNotifications(); NSNotificationCenter.DefaultCenter.RemoveObserver(this); - if (TintColor != null) - Ring.ResetStyle(TintColor); - CancelRingLayerAnimation(); StringLabel.RemoveFromSuperview(); SpinnerView.RemoveFromSuperview(); diff --git a/BTProgressHUD/ProgressHUDAppearance.cs b/BTProgressHUD/ProgressHUDAppearance.cs index e4fdda8..ad76626 100644 --- a/BTProgressHUD/ProgressHUDAppearance.cs +++ b/BTProgressHUD/ProgressHUDAppearance.cs @@ -5,7 +5,7 @@ namespace BigTed; public static class ProgressHUDAppearance { - public static UIColor DefaultHudBackgroundColour { get; } = + public static UIColor DefaultHudBackgroundColor { get; } = OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13) ? UIColor.SystemBackground.ColorWithAlpha(0.8f) : UIColor.White.ColorWithAlpha(0.8f); @@ -15,20 +15,100 @@ public static class ProgressHUDAppearance UIColor.Label.ColorWithAlpha(0.8f) : UIColor.FromWhiteAlpha(0.0f, 0.8f); + public static UIColor DefaultHudTextColor { get; } = + OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13) ? + UIColor.Label.ColorWithAlpha(0.8f) : + UIColor.FromWhiteAlpha(0.0f, 0.8f); + + public static UIColor DefaultHudButtonTextColor { get; } = + OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13) ? + UIColor.Label.ColorWithAlpha(0.8f) : + UIColor.FromWhiteAlpha(0.0f, 0.8f); + public static UIColor DefaultHudToastBackgroundColor { get; } = UIColor.Clear; public static UIFont DefaultHudFont { get; } = UIFont.BoldSystemFontOfSize(16f); public static UITextAlignment DefaultHudTextAlignment { get; } = UITextAlignment.Center; + + public static UIColor DefaultRingColor = UIColor.SystemBlue; + + public static UIColor DefaultRingBackgroundColor = + OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsMacCatalystVersionAtLeast(13) + ? UIColor.SystemBackground + : UIColor.White; + public const float DefaultRingRadius = 14f; public const float DefaultRingThickness = 1f; + public const float DefaultHudCornerRadius = 10f; + public const double DefaultProgressUpdateInterval = 300; + /// + /// Get or set definite progress indicator ring radius to control its size + /// public static float RingRadius { get; set; } = DefaultRingRadius; + + /// + /// Get or set definite progress indicator ring stroke thickness + /// public static float RingThickness { get; set; } = DefaultRingThickness; + /// + /// Get or set update interval for definite progress indicator ring animation + /// + public static double RingProgressUpdateInterval { get; set; } = DefaultProgressUpdateInterval; - public static UIColor HudBackgroundColour { get; set; } = DefaultHudBackgroundColour; + /// + /// Get or set definite progress indicator ring foreground color + /// + public static UIColor RingColor { get; set; } = DefaultRingColor; + + /// + /// Get or set definite progress indicator ring background color + /// + public static UIColor RingBackgroundColor { get; set; } = DefaultRingBackgroundColor; + + /// + /// Get or set hud corner radius + /// + public static float HudCornerRadius { get; set; } = DefaultHudCornerRadius; + + /// + /// Get or set hud background color + /// + public static UIColor HudBackgroundColor { get; set; } = DefaultHudBackgroundColor; + + /// + /// Get or set image tint color + /// public static UIColor HudForegroundColor { get; set; } = DefaultHudForegroundColor; + + /// + /// Get or set background color of toast + /// public static UIColor HudToastBackgroundColor { get; set; } = DefaultHudToastBackgroundColor; + + /// + /// Get or set font used for texts shown in hud + /// public static UIFont HudFont { get; set; } = DefaultHudFont; + + /// + /// Get or set color of texts shown in hud + /// + public static UIColor HudTextColor { get; set; } = DefaultHudTextColor; + + /// + /// Get or set font to use for cancel button + /// + public static UIFont HudButtonFont { get; set; } = DefaultHudFont; + + /// + /// Get or set text color on cancel button + /// + public static UIColor HudButtonTextColor { get; set; } = DefaultHudButtonTextColor; + + /// + /// Get or set alignment on texts shown in hud + /// public static UITextAlignment HudTextAlignment { get; set; } = DefaultHudTextAlignment; public static UIImage? ErrorImage { get; set; } @@ -40,4 +120,23 @@ public static class ProgressHUDAppearance public static UIImage? ErrorOutlineFullImage { get; set; } public static UIImage? SuccessOutlineFullImage { get; set; } public static UIImage? InfoOutlineFullImage { get; set; } + + public static void ResetToDefaults() + { + RingRadius = DefaultRingRadius; + RingThickness = DefaultRingThickness; + RingProgressUpdateInterval = DefaultProgressUpdateInterval; + RingColor = DefaultRingColor; + RingBackgroundColor = DefaultRingBackgroundColor; + + HudCornerRadius = DefaultHudCornerRadius; + HudBackgroundColor = DefaultHudBackgroundColor; + HudForegroundColor = DefaultHudForegroundColor; + HudToastBackgroundColor = DefaultHudToastBackgroundColor; + HudFont = DefaultHudFont; + HudButtonFont = DefaultHudFont; + HudTextColor = DefaultHudTextColor; + HudButtonTextColor = DefaultHudButtonTextColor; + HudTextAlignment = DefaultHudTextAlignment; + } } diff --git a/BTProgressHUD/Ring.cs b/BTProgressHUD/Ring.cs deleted file mode 100644 index 71ef6e4..0000000 --- a/BTProgressHUD/Ring.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using UIKit; - -namespace BigTed -{ - public class Ring - { - /// - /// Ring color - /// - public UIColor Color = UIColor.White; - /// - /// Background color - /// - public UIColor BackgroundColor = UIColor.DarkGray; - /// - /// Progress update interval in milliseconds - /// - public double ProgressUpdateInterval = 300; - - public void ResetStyle(UIColor colorToUse) - { - Color = colorToUse; - if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsMacCatalystVersionAtLeast(13)) - { - BackgroundColor = UIColor.SystemBackground; - } - else - { - BackgroundColor = UIColor.White; - } - ProgressUpdateInterval = 300; - } - } -} - diff --git a/BTProgressHUDDemo/MainViewModel.cs b/BTProgressHUDDemo/MainViewModel.cs index bf87f68..6f4b0a3 100644 --- a/BTProgressHUDDemo/MainViewModel.cs +++ b/BTProgressHUDDemo/MainViewModel.cs @@ -2,6 +2,7 @@ using System.Windows.Input; using BigTed; using Foundation; +using UIKit; namespace BTProgressHUDDemo2 { @@ -12,13 +13,18 @@ public class MainViewModel public MainViewModel() { - this.Items = new[] - { + Items = + [ + Create("Dismiss", () => + { + BTProgressHUD.Dismiss(); + }, false), Create("Show", () => BTProgressHUD.Show(), true), Create("Cancel problem 3", () => BTProgressHUD.Show("Cancel", () => KillAfter(), "Cancel and text"), false), Create("Cancel problem 2", () => BTProgressHUD.Show("Cancel", () => KillAfter()), false), Create("Cancel problem", () => BTProgressHUD.Show("Cancel", () => KillAfter(), "This is a multilinetext\nSome more text\n more text\n and again more text"), false), - Create("Show Message", () => BTProgressHUD.Show("Processing your image", -1, MaskType.Black), false), + Create("Show Message", () => + BTProgressHUD.Show("Processing your image", 10, MaskType.Black), true), Create("Show Success", () => { BTProgressHUD.ShowSuccessWithStatus("Great success!"); @@ -68,12 +74,6 @@ public MainViewModel() { BTProgressHUD.ShowToast("Hello from the toast", false, 1000); }, false), - - Create("Dismiss", () => - { - BTProgressHUD.Dismiss(); - }, false), - Create("Progress", () => { progress = 0; @@ -98,12 +98,21 @@ public MainViewModel() }); NSRunLoop.Current.AddTimer(timer, NSRunLoopMode.Common); }, false), - - Create("Dismiss", () => - { - BTProgressHUD.Dismiss(); - }, false) - }; + Create("Customize", () => + { + ProgressHUDAppearance.RingColor = UIColor.Green; + ProgressHUDAppearance.RingBackgroundColor = UIColor.Brown; + + ProgressHUDAppearance.HudBackgroundColor = UIColor.Yellow; + ProgressHUDAppearance.HudTextColor = UIColor.Purple; + ProgressHUDAppearance.HudButtonTextColor = UIColor.Orange; + ProgressHUDAppearance.HudCornerRadius = 2; + ProgressHUDAppearance.HudTextAlignment = UITextAlignment.Left; + ProgressHUDAppearance.HudTextColor = UIColor.Cyan; + ProgressHUDAppearance.HudToastBackgroundColor = UIColor.Blue; + }, false), + Create("Reset Customization", ProgressHUDAppearance.ResetToDefaults, false) + ]; } @@ -147,4 +156,4 @@ public record CommandItem( string Text, ICommand Command ); -} \ No newline at end of file +} diff --git a/BTProgressHUDDemo/MauiProgram.cs b/BTProgressHUDDemo/MauiProgram.cs index b893b9e..00403ab 100644 --- a/BTProgressHUDDemo/MauiProgram.cs +++ b/BTProgressHUDDemo/MauiProgram.cs @@ -18,8 +18,6 @@ public static MauiApp CreateMauiApp() #if IOS || MACCATALYST ProgressHUD.Initialize(); - ProgressHUDAppearance.HudFont = UIFont.PreferredHeadline; - ProgressHUDAppearance.HudForegroundColor = UIColor.Purple; #endif return builder.Build(); From 2b71fe2291b5130ce5b8b2b458ec34b9a815593f Mon Sep 17 00:00:00 2001 From: Tomasz Cielecki Date: Mon, 13 May 2024 21:10:14 +0200 Subject: [PATCH 4/7] Rename property to HudImageTintColor --- BTProgressHUD/ProgressHUD.cs | 2 +- BTProgressHUD/ProgressHUDAppearance.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/BTProgressHUD/ProgressHUD.cs b/BTProgressHUD/ProgressHUD.cs index 0888706..39941ac 100644 --- a/BTProgressHUD/ProgressHUD.cs +++ b/BTProgressHUD/ProgressHUD.cs @@ -625,7 +625,7 @@ private void ShowImageWorker(UIImage image, string? status, MaskType maskType, T Show(null, -1F, maskType); } - ImageView.TintColor = ProgressHUDAppearance.HudForegroundColor; + ImageView.TintColor = ProgressHUDAppearance.HudImageTintColor; ImageView.Image = image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); ImageView.Hidden = false; StringLabel.Text = status; diff --git a/BTProgressHUD/ProgressHUDAppearance.cs b/BTProgressHUD/ProgressHUDAppearance.cs index ad76626..6c4d169 100644 --- a/BTProgressHUD/ProgressHUDAppearance.cs +++ b/BTProgressHUD/ProgressHUDAppearance.cs @@ -10,7 +10,7 @@ public static class ProgressHUDAppearance UIColor.SystemBackground.ColorWithAlpha(0.8f) : UIColor.White.ColorWithAlpha(0.8f); - public static UIColor DefaultHudForegroundColor { get; } = + public static UIColor DefaultHudImageTintColor { get; } = OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13) ? UIColor.Label.ColorWithAlpha(0.8f) : UIColor.FromWhiteAlpha(0.0f, 0.8f); @@ -79,7 +79,7 @@ public static class ProgressHUDAppearance /// /// Get or set image tint color /// - public static UIColor HudForegroundColor { get; set; } = DefaultHudForegroundColor; + public static UIColor HudImageTintColor { get; set; } = DefaultHudImageTintColor; /// /// Get or set background color of toast @@ -131,7 +131,7 @@ public static void ResetToDefaults() HudCornerRadius = DefaultHudCornerRadius; HudBackgroundColor = DefaultHudBackgroundColor; - HudForegroundColor = DefaultHudForegroundColor; + HudImageTintColor = DefaultHudImageTintColor; HudToastBackgroundColor = DefaultHudToastBackgroundColor; HudFont = DefaultHudFont; HudButtonFont = DefaultHudFont; From 240e1c8ae26bbf511a22295dfb390e59030fcf01 Mon Sep 17 00:00:00 2001 From: Tomasz Cielecki Date: Mon, 13 May 2024 21:13:50 +0200 Subject: [PATCH 5/7] Update readme --- README.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f138564..62cd82b 100644 --- a/README.md +++ b/README.md @@ -91,12 +91,17 @@ You can use the timeout parameter of ShowImage to control the time before it's d You can customize the appearance of the ProgressHUD through the `ProgressHUDAppearance` class where you can controll the following options: +- Corner Radius - Background Color -- Foreground Color -- Font -- TextAlignment +- Image Tint Color +- Text Font +- Button Font +- Text Color +- Button Text Color +- Text Alignment - Ring Radius -- Ring Thickness +- Ring Stroke Thickness +- Ring Color - Images and the various outlined/full versions for: - Error - Success From db4242169a976c2f1de538d0d5c1a415015322e2 Mon Sep 17 00:00:00 2001 From: Tomasz Cielecki Date: Mon, 13 May 2024 21:31:12 +0200 Subject: [PATCH 6/7] Clean up dupes --- BTProgressHUD/ProgressHUDAppearance.cs | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/BTProgressHUD/ProgressHUDAppearance.cs b/BTProgressHUD/ProgressHUDAppearance.cs index 6c4d169..012261a 100644 --- a/BTProgressHUD/ProgressHUDAppearance.cs +++ b/BTProgressHUD/ProgressHUDAppearance.cs @@ -10,17 +10,7 @@ public static class ProgressHUDAppearance UIColor.SystemBackground.ColorWithAlpha(0.8f) : UIColor.White.ColorWithAlpha(0.8f); - public static UIColor DefaultHudImageTintColor { get; } = - OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13) ? - UIColor.Label.ColorWithAlpha(0.8f) : - UIColor.FromWhiteAlpha(0.0f, 0.8f); - - public static UIColor DefaultHudTextColor { get; } = - OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13) ? - UIColor.Label.ColorWithAlpha(0.8f) : - UIColor.FromWhiteAlpha(0.0f, 0.8f); - - public static UIColor DefaultHudButtonTextColor { get; } = + public static UIColor DefaultForegroundColor { get; } = OperatingSystem.IsIOSVersionAtLeast(13, 0) || OperatingSystem.IsMacCatalystVersionAtLeast(13) ? UIColor.Label.ColorWithAlpha(0.8f) : UIColor.FromWhiteAlpha(0.0f, 0.8f); @@ -34,7 +24,7 @@ public static class ProgressHUDAppearance public static UIColor DefaultRingBackgroundColor = OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsMacCatalystVersionAtLeast(13) ? UIColor.SystemBackground - : UIColor.White; + : DefaultHudBackgroundColor; public const float DefaultRingRadius = 14f; public const float DefaultRingThickness = 1f; @@ -79,7 +69,7 @@ public static class ProgressHUDAppearance /// /// Get or set image tint color /// - public static UIColor HudImageTintColor { get; set; } = DefaultHudImageTintColor; + public static UIColor HudImageTintColor { get; set; } = DefaultForegroundColor; /// /// Get or set background color of toast @@ -94,7 +84,7 @@ public static class ProgressHUDAppearance /// /// Get or set color of texts shown in hud /// - public static UIColor HudTextColor { get; set; } = DefaultHudTextColor; + public static UIColor HudTextColor { get; set; } = DefaultForegroundColor; /// /// Get or set font to use for cancel button @@ -104,7 +94,7 @@ public static class ProgressHUDAppearance /// /// Get or set text color on cancel button /// - public static UIColor HudButtonTextColor { get; set; } = DefaultHudButtonTextColor; + public static UIColor HudButtonTextColor { get; set; } = DefaultForegroundColor; /// /// Get or set alignment on texts shown in hud @@ -131,12 +121,12 @@ public static void ResetToDefaults() HudCornerRadius = DefaultHudCornerRadius; HudBackgroundColor = DefaultHudBackgroundColor; - HudImageTintColor = DefaultHudImageTintColor; + HudImageTintColor = DefaultForegroundColor; HudToastBackgroundColor = DefaultHudToastBackgroundColor; HudFont = DefaultHudFont; HudButtonFont = DefaultHudFont; - HudTextColor = DefaultHudTextColor; - HudButtonTextColor = DefaultHudButtonTextColor; + HudTextColor = DefaultForegroundColor; + HudButtonTextColor = DefaultForegroundColor; HudTextAlignment = DefaultHudTextAlignment; } } From f35db92bf26e2b9f1bc2a9a05bbeaae955f7bee1 Mon Sep 17 00:00:00 2001 From: Tomasz Cielecki Date: Mon, 13 May 2024 21:37:04 +0200 Subject: [PATCH 7/7] Make sample a bit nicer --- BTProgressHUDDemo/MainPage.xaml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/BTProgressHUDDemo/MainPage.xaml b/BTProgressHUDDemo/MainPage.xaml index a85c232..2ddb54c 100644 --- a/BTProgressHUDDemo/MainPage.xaml +++ b/BTProgressHUDDemo/MainPage.xaml @@ -10,21 +10,17 @@ - + - +