From 6aa22257ec4d5694b29e0fc8c715a7a3ad4a1ab8 Mon Sep 17 00:00:00 2001 From: flexih Date: Fri, 21 Apr 2023 10:51:54 +0800 Subject: [PATCH] Supports spin --- Example Apps/iOS Example/Scenes/PresetsController.swift | 6 ++++++ Sources/SPIndicator/SPIndicatorIconPreset.swift | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Example Apps/iOS Example/Scenes/PresetsController.swift b/Example Apps/iOS Example/Scenes/PresetsController.swift index 00b9127..9fe29ec 100644 --- a/Example Apps/iOS Example/Scenes/PresetsController.swift +++ b/Example Apps/iOS Example/Scenes/PresetsController.swift @@ -104,6 +104,12 @@ class PresetsController: SPDiffableTableController { message: "Try again", preset: .error ), + IndicatorPresetModel( + name: "Spin", + title: "Spin", + message: "Animatable", + preset: .spin(.medium) + ), IndicatorPresetModel( name: "Custom Image", title: "Custom Image", diff --git a/Sources/SPIndicator/SPIndicatorIconPreset.swift b/Sources/SPIndicator/SPIndicatorIconPreset.swift index 299f42c..4103c35 100644 --- a/Sources/SPIndicator/SPIndicatorIconPreset.swift +++ b/Sources/SPIndicator/SPIndicatorIconPreset.swift @@ -29,7 +29,7 @@ public enum SPIndicatorIconPreset { case done case error - + case spin(_ style: UIActivityIndicatorView.Style) case custom(_ image: UIImage) } @@ -46,6 +46,10 @@ public extension SPIndicatorIconPreset { let view = SPIndicatorIconErrorView() view.tintColor = UIColor.systemRed return view + case .spin(let style): + let view = UIActivityIndicatorView(style: style) + view.startAnimating() + return view case .custom(let image): let imageView = UIImageView(image: image) imageView.contentMode = .scaleAspectFit @@ -57,6 +61,7 @@ public extension SPIndicatorIconPreset { switch self { case .error: return .error case .done: return .success + case .spin(_): return .none case .custom(_): return .success } } @@ -96,6 +101,8 @@ public extension SPIndicatorLayout { iconSize = .init(width: 14, height: 14) margins.left = 19 margins.right = margins.left + case .spin(_): + self.init() case .custom(_): self.init() }