修改pods

This commit is contained in:
2025-09-20 17:13:38 +08:00
parent 7787b3ee30
commit 28ff2b0264
5251 changed files with 345029 additions and 285168 deletions

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2011-2018 Sam Vermette, Tobias Tiemerding and contributors.
Copyright (c) 2011-2023 Sam Vermette, Tobias Totzek and contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -3,19 +3,29 @@
![Pod Version](https://img.shields.io/cocoapods/v/SVProgressHUD.svg?style=flat)
![Pod Platform](https://img.shields.io/cocoapods/p/SVProgressHUD.svg?style=flat)
![Pod License](https://img.shields.io/cocoapods/l/SVProgressHUD.svg?style=flat)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-green.svg?style=flat)](https://github.com/Carthage/Carthage)
[![SwiftPM compatible](https://img.shields.io/badge/SwiftPM-compatible-brightgreen.svg)](https://swift.org/package-manager/)
[![CocoaPods compatible](https://img.shields.io/badge/CocoaPods-compatible-green.svg?style=flat)](https://cocoapods.org)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-green.svg?style=flat)](https://github.com/Carthage/Carthage)
`SVProgressHUD` is a clean and easy-to-use HUD meant to display the progress of an ongoing task on iOS and tvOS.
![SVProgressHUD](http://f.cl.ly/items/2G1F1Z0M0k0h2U3V1p39/SVProgressHUD.gif)
## Demo
Try `SVProgressHUD` on [Appetize.io](https://appetize.io/app/p8r2cvy8kq74x7q7tjqf5gyatr).
![SVProgressHUD](https://raw.githubusercontent.com/SVProgressHUD/SVProgressHUD/master/Images/SVProgressHUD.png)
## Installation
### Swift Package Manager
[Swift Package Manager](https://swift.org/package-manager/) (SwiftPM) is a tool for managing the distribution of Swift code. It simplifies the process of managing Swift package dependencies.
To integrate `SVProgressHUD` into your project using SwiftPM:
1. In Xcode, select **File > Add Package Dependency**.
2. Enter the following package repository URL: https://github.com/SVProgressHUD/SVProgressHUD.git
3. Choose the appropriate version (e.g. a specific version, branch, or commit).
4. Add `SVProgressHUD` to your target dependencies.
`SVProgressHUD` requires at least Swift tools version 5.3.
### From CocoaPods
[CocoaPods](http://cocoapods.org) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like `SVProgressHUD` in your projects. First, add the following line to your [Podfile](http://guides.cocoapods.org/using/using-cocoapods.html):
@@ -56,7 +66,9 @@ Run `carthage bootstrap` to build the framework in your repository's Carthage di
## Swift
Even though `SVProgressHUD` is written in Objective-C, it can be used in Swift with no hassle. If you use [CocoaPods](http://cocoapods.org) add the following line to your [Podfile](http://guides.cocoapods.org/using/using-cocoapods.html):
Even though `SVProgressHUD` is written in Objective-C, it can be used in Swift with no hassle.
If you use [CocoaPods](http://cocoapods.org) add the following line to your [Podfile](http://guides.cocoapods.org/using/using-cocoapods.html):
```ruby
use_frameworks!
@@ -68,11 +80,13 @@ If you added `SVProgressHUD` manually, just add a [bridging header](https://deve
(see sample Xcode project in `/Demo`)
`SVProgressHUD` is created as a singleton (i.e. it doesn't need to be explicitly allocated and instantiated; you directly call `[SVProgressHUD method]`).
`SVProgressHUD` is created as a singleton (i.e. it doesn't need to be explicitly allocated and instantiated; you directly call `[SVProgressHUD method]` / `SVProgressHUD.method()`).
**Use `SVProgressHUD` wisely! Only use it if you absolutely need to perform a task before taking the user forward. Bad use case examples: pull to refresh, infinite scrolling, sending message.**
Using `SVProgressHUD` in your app will usually look as simple as this (using Grand Central Dispatch):
Using `SVProgressHUD` in your app will usually look as simple as this.
**Objective-C:**
```objective-c
[SVProgressHUD show];
@@ -84,6 +98,18 @@ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
});
```
**Swift:**
```swift
SVProgressHUD.show()
DispatchQueue.global(qos: .default).async {
// time-consuming task
DispatchQueue.main.async {
SVProgressHUD.dismiss()
}
}
```
### Showing the HUD
You can show the status of indeterminate tasks using one of the following:
@@ -115,9 +141,9 @@ If you'd like to stack HUDs, you can balance out every show call using:
+ (void)popActivity;
```
The HUD will get dismissed once the popActivity calls will match the number of show calls.
The HUD will get dismissed once the `popActivity` calls will match the number of show calls.
Or show a confirmation glyph before before getting dismissed a little bit later. The display time depends on `minimumDismissTimeInterval` and the length of the given string.
Or show an image with status before getting dismissed a little bit later. The display time depends on `minimumDismissTimeInterval` and the length of the given string.
```objective-c
+ (void)showInfoWithStatus:(NSString*)string;
@@ -128,53 +154,27 @@ Or show a confirmation glyph before before getting dismissed a little bit later.
## Customization
`SVProgressHUD` can be customized via the following methods:
`SVProgressHUD` is designed with flexibility in mind, providing a myriad of customization options to fit the look and feel of your application seamlessly.
```objective-c
+ (void)setDefaultStyle:(SVProgressHUDStyle)style; // default is SVProgressHUDStyleLight
+ (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType; // default is SVProgressHUDMaskTypeNone
+ (void)setDefaultAnimationType:(SVProgressHUDAnimationType)type; // default is SVProgressHUDAnimationTypeFlat
+ (void)setContainerView:(UIView*)containerView; // default is window level
+ (void)setMinimumSize:(CGSize)minimumSize; // default is CGSizeZero, can be used to avoid resizing
+ (void)setRingThickness:(CGFloat)width; // default is 2 pt
+ (void)setRingRadius:(CGFloat)radius; // default is 18 pt
+ (void)setRingNoTextRadius:(CGFloat)radius; // default is 24 pt
+ (void)setCornerRadius:(CGFloat)cornerRadius; // default is 14 pt
+ (void)setBorderColor:(nonnull UIColor*)color; // default is nil
+ (void)setBorderWidth:(CGFloat)width; // default is 0
+ (void)setFont:(UIFont*)font; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
+ (void)setForegroundColor:(UIColor*)color; // default is [UIColor blackColor], only used for SVProgressHUDStyleCustom
+ (void)setBackgroundColor:(UIColor*)color; // default is [UIColor whiteColor], only used for SVProgressHUDStyleCustom
+ (void)setBackgroundLayerColor:(UIColor*)color; // default is [UIColor colorWithWhite:0 alpha:0.4], only used for SVProgressHUDMaskTypeCustom
+ (void)setImageViewSize:(CGSize)size; // default is 28x28 pt
+ (void)setShouldTintImages:(BOOL)shouldTintImages; // default is YES
+ (void)setInfoImage:(UIImage*)image; // default is the bundled info image provided by Freepik
+ (void)setSuccessImage:(UIImage*)image; // default is bundled success image from Freepik
+ (void)setErrorImage:(UIImage*)image; // default is bundled error image from Freepik
+ (void)setViewForExtension:(UIView*)view; // default is nil, only used if #define SV_APP_EXTENSIONS is set
+ (void)setGraceTimeInterval:(NSTimeInterval)interval; // default is 0 seconds
+ (void)setMinimumDismissTimeInterval:(NSTimeInterval)interval; // default is 5.0 seconds
+ (void)setMaximumDismissTimeInterval:(NSTimeInterval)interval; // default is CGFLOAT_MAX
+ (void)setFadeInAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds
+ (void)setFadeOutAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds
+ (void)setMaxSupportedWindowLevel:(UIWindowLevel)windowLevel; // default is UIWindowLevelNormal
+ (void)setHapticsEnabled:(BOOL)hapticsEnabled; // default is NO
```
* Appearance: Make use of the `UI_APPEARANCE_SELECTOR` to adjust styles, colors, fonts, size, and images app-wide.
* Behavior: Control visibility durations, display delays, and animation speeds.
* Feedback: Enhance the user experience with options for haptic feedback and motion effects.
Additionally `SVProgressHUD` supports the `UIAppearance` protocol for most of the above methods.
For a comprehensive list of properties and detailed explanations, refer to the `SVProgressHUD.h` file in the API documentation.
### Hint
As standard `SVProgressHUD` offers two preconfigured styles:
As standard `SVProgressHUD` offers three preconfigured styles:
* `SVProgressHUDStyleAutomatic`: Automatically switch between the light and dark style
* `SVProgressHUDStyleLight`: White background with black spinner and text
* `SVProgressHUDStyleDark`: Black background with white spinner and text
If you want to use custom colors use `setForegroundColor` and `setBackgroundColor:`. These implicitly set the HUD's style to `SVProgressHUDStyleCustom`.
If you want to use custom colors use `setForegroundColor:` and/or `setBackgroundColor:`. These implicitly set the HUD's style to `SVProgressHUDStyleCustom`.
## Haptic Feedback
For users with newer devices (starting with the iPhone 7), `SVProgressHUD` can automatically trigger haptic feedback depending on which HUD is being displayed. The feedback maps as follows:
Available on iPhone 7 and newer, `SVProgressHUD` can automatically trigger haptic feedback depending on which HUD is being displayed. The feedback maps as follows:
* `showSuccessWithStatus:` <-> `UINotificationFeedbackTypeSuccess`
* `showInfoWithStatus:` <-> `UINotificationFeedbackTypeWarning`
@@ -182,11 +182,10 @@ For users with newer devices (starting with the iPhone 7), `SVProgressHUD` can a
To enable this functionality, use `setHapticsEnabled:`.
Users with devices prior to iPhone 7 will have no change in functionality.
## Notifications
`SVProgressHUD` posts four notifications via `NSNotificationCenter` in response to being shown/dismissed:
* `SVProgressHUDWillAppearNotification` when the show animation starts
* `SVProgressHUDDidAppearNotification` when the show animation completes
* `SVProgressHUDWillDisappearNotification` when the dismiss animation starts
@@ -194,11 +193,11 @@ Users with devices prior to iPhone 7 will have no change in functionality.
Each notification passes a `userInfo` dictionary holding the HUD's status string (if any), retrievable via `SVProgressHUDStatusUserInfoKey`.
`SVProgressHUD` also posts `SVProgressHUDDidReceiveTouchEventNotification` when users touch on the overall screen or `SVProgressHUDDidTouchDownInsideNotification` when a user touches on the HUD directly. For this notifications `userInfo` is not passed but the object parameter contains the `UIEvent` that related to the touch.
`SVProgressHUD` also posts `SVProgressHUDDidReceiveTouchEventNotification` when users touch on the overall screen or `SVProgressHUDDidTouchDownInsideNotification` when a user touches on the HUD directly. For these notifications `userInfo` is not passed but the object parameter contains the `UIEvent` that related to the touch.
## App Extensions
When using `SVProgressHUD` in an App Extension, `#define SV_APP_EXTENSIONS` to avoid using unavailable APIs. Additionally call `setViewForExtension:` from your extensions view controller with `self.view`.
When using `SVProgressHUD` in an App Extension, `#define SV_APP_EXTENSIONS` to avoid using unavailable APIs. This will be done automatically when using the `AppExtension` CocoaPods subspec. Additionally, call `setViewForExtension:` from your extensions view controller with `self.view`.
## Contributing to this project
@@ -211,8 +210,12 @@ review the guidelines written by [Nicolas Gallagher](https://github.com/necolas)
## License
`SVProgressHUD` is distributed under the terms and conditions of the [MIT license](https://github.com/SVProgressHUD/SVProgressHUD/blob/master/LICENSE.txt). The success, error and info icons are made by [Freepik](http://www.freepik.com) from [Flaticon](http://www.flaticon.com) and are licensed under [Creative Commons BY 3.0](http://creativecommons.org/licenses/by/3.0/).
`SVProgressHUD` is distributed under the terms and conditions of the [MIT license](https://github.com/SVProgressHUD/SVProgressHUD/blob/master/LICENSE). The success, error and info icons used on iOS 12 are made by [Freepik](http://www.freepik.com) from [Flaticon](https://www.flaticon.com) and are licensed under [Creative Commons BY 3.0](https://creativecommons.org/licenses/by/3.0/).
## Privacy
`SVProgressHUD` does not collect any data. A [privacy manifest file](https://developer.apple.com/documentation/bundleresources/privacy_manifest_files) is [provided](SVProgressHUD/PrivacyInfo.xcprivacy).
## Credits
`SVProgressHUD` is brought to you by [Sam Vermette](http://samvermette.com), [Tobias Tiemerding](http://tiemerding.com) and [contributors to the project](https://github.com/SVProgressHUD/SVProgressHUD/contributors). If you're using `SVProgressHUD` in your project, attribution would be very appreciated.
`SVProgressHUD` is brought to you by Sam Vermette, [Tobias Totzek](https://totzek.me) and [contributors to the project](https://github.com/SVProgressHUD/SVProgressHUD/contributors). If you're using `SVProgressHUD` in your project, attribution would be very appreciated.

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyTracking</key>
<false/>
<key>NSPrivacyCollectedDataTypes</key>
<array/>
<key>NSPrivacyTrackingDomains</key>
<array/>
<key>NSPrivacyAccessedAPITypes</key>
<array/>
</dict>
</plist>

View File

@@ -2,7 +2,7 @@
// SVIndefiniteAnimatedView.h
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2014-2018 Guillaume Campagna. All rights reserved.
// Copyright (c) 2014-2023 Guillaume Campagna and contributors. All rights reserved.
//
#import <UIKit/UIKit.h>

View File

@@ -2,7 +2,7 @@
// SVIndefiniteAnimatedView.m
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2014-2018 Guillaume Campagna. All rights reserved.
// Copyright (c) 2014-2023 Guillaume Campagna and contributors. All rights reserved.
//
#import "SVIndefiniteAnimatedView.h"
@@ -25,9 +25,18 @@
}
}
- (void)layoutSubviews {
[super layoutSubviews];
[self layoutAnimatedLayer];
}
- (void)layoutAnimatedLayer {
CALayer *layer = self.indefiniteAnimatedLayer;
[self.layer addSublayer:layer];
if (!layer.superlayer) {
[self.layer addSublayer:layer];
}
CGFloat widthDiff = CGRectGetWidth(self.bounds) - CGRectGetWidth(layer.bounds);
CGFloat heightDiff = CGRectGetHeight(self.bounds) - CGRectGetHeight(layer.bounds);
@@ -51,13 +60,9 @@
CALayer *maskLayer = [CALayer layer];
NSBundle *bundle = [NSBundle bundleForClass:[SVProgressHUD class]];
NSURL *url = [bundle URLForResource:@"SVProgressHUD" withExtension:@"bundle"];
NSBundle *imageBundle = [NSBundle bundleWithURL:url];
NSBundle *imageBundle = [SVProgressHUD imageBundle];
NSString *path = [imageBundle pathForResource:@"angle-mask" ofType:@"png"];
maskLayer.contents = (__bridge id)[[UIImage imageWithContentsOfFile:path] CGImage];
maskLayer.contents = (__bridge id)[[UIImage imageNamed:@"angle-mask.png" inBundle:imageBundle compatibleWithTraitCollection:nil] CGImage];
maskLayer.frame = _indefiniteAnimatedLayer.bounds;
_indefiniteAnimatedLayer.mask = maskLayer;

View File

@@ -2,7 +2,7 @@
// SVProgressAnimatedView.h
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2017-2018 Tobias Tiemerding. All rights reserved.
// Copyright (c) 2017-2023 Tobias Totzek and contributors. All rights reserved.
//
#import <UIKit/UIKit.h>

View File

@@ -2,7 +2,7 @@
// SVProgressAnimatedView.m
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2017-2018 Tobias Tiemerding. All rights reserved.
// Copyright (c) 2017-2023 Tobias Totzek and contributors. All rights reserved.
//
#import "SVProgressAnimatedView.h"

View File

@@ -2,7 +2,7 @@
// SVProgressHUD.h
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2011-2018 Sam Vermette and contributors. All rights reserved.
// Copyright (c) 2011-2023 Sam Vermette and contributors. All rights reserved.
//
#import <UIKit/UIKit.h>
@@ -17,23 +17,46 @@ extern NSString * _Nonnull const SVProgressHUDDidAppearNotification;
extern NSString * _Nonnull const SVProgressHUDStatusUserInfoKey;
/// Represents the appearance style of the HUD.
typedef NS_ENUM(NSInteger, SVProgressHUDStyle) {
SVProgressHUDStyleLight, // default style, white HUD with black text, HUD background will be blurred
SVProgressHUDStyleDark, // black HUD and white text, HUD background will be blurred
SVProgressHUDStyleCustom // uses the fore- and background color properties
/// White HUD with black text. HUD background will be blurred.
SVProgressHUDStyleLight NS_SWIFT_NAME(light),
/// Black HUD with white text. HUD background will be blurred.
SVProgressHUDStyleDark NS_SWIFT_NAME(dark),
/// Uses the fore- and background color properties.
SVProgressHUDStyleCustom NS_SWIFT_NAME(custom),
/// Automatically switch between light or dark mode appearance.
SVProgressHUDStyleAutomatic NS_SWIFT_NAME(automatic)
};
/// Represents the type of mask to be applied when the HUD is displayed.
typedef NS_ENUM(NSUInteger, SVProgressHUDMaskType) {
SVProgressHUDMaskTypeNone = 1, // default mask type, allow user interactions while HUD is displayed
SVProgressHUDMaskTypeClear, // don't allow user interactions with background objects
SVProgressHUDMaskTypeBlack, // don't allow user interactions with background objects and dim the UI in the back of the HUD (as seen in iOS 7 and above)
SVProgressHUDMaskTypeGradient, // don't allow user interactions with background objects and dim the UI with a a-la UIAlertView background gradient (as seen in iOS 6)
SVProgressHUDMaskTypeCustom // don't allow user interactions with background objects and dim the UI in the back of the HUD with a custom color
/// Allow user interactions while HUD is displayed.
SVProgressHUDMaskTypeNone NS_SWIFT_NAME(none) = 1,
/// Don't allow user interactions with background objects.
SVProgressHUDMaskTypeClear NS_SWIFT_NAME(clear),
/// Don't allow user interactions and dim the UI behind the HUD (as in iOS 7+).
SVProgressHUDMaskTypeBlack NS_SWIFT_NAME(black),
/// Don't allow user interactions and dim the UI with an UIAlertView-like background gradient (as in iOS 6).
SVProgressHUDMaskTypeGradient NS_SWIFT_NAME(gradient),
/// Don't allow user interactions and dim the UI behind the HUD with a custom color.
SVProgressHUDMaskTypeCustom NS_SWIFT_NAME(custom)
};
/// Represents the animation type of the HUD when it's shown or hidden.
typedef NS_ENUM(NSUInteger, SVProgressHUDAnimationType) {
SVProgressHUDAnimationTypeFlat, // default animation type, custom flat animation (indefinite animated ring)
SVProgressHUDAnimationTypeNative // iOS native UIActivityIndicatorView
/// Custom flat animation (indefinite animated ring).
SVProgressHUDAnimationTypeFlat NS_SWIFT_NAME(flat),
/// iOS native UIActivityIndicatorView.
SVProgressHUDAnimationTypeNative NS_SWIFT_NAME(native)
};
typedef void (^SVProgressHUDShowCompletion)(void);
@@ -43,104 +66,326 @@ typedef void (^SVProgressHUDDismissCompletion)(void);
#pragma mark - Customization
@property (assign, nonatomic) SVProgressHUDStyle defaultStyle UI_APPEARANCE_SELECTOR; // default is SVProgressHUDStyleLight
@property (assign, nonatomic) SVProgressHUDMaskType defaultMaskType UI_APPEARANCE_SELECTOR; // default is SVProgressHUDMaskTypeNone
@property (assign, nonatomic) SVProgressHUDAnimationType defaultAnimationType UI_APPEARANCE_SELECTOR; // default is SVProgressHUDAnimationTypeFlat
@property (strong, nonatomic, nullable) UIView *containerView; // if nil then use default window level
@property (assign, nonatomic) CGSize minimumSize UI_APPEARANCE_SELECTOR; // default is CGSizeZero, can be used to avoid resizing for a larger message
@property (assign, nonatomic) CGFloat ringThickness UI_APPEARANCE_SELECTOR; // default is 2 pt
@property (assign, nonatomic) CGFloat ringRadius UI_APPEARANCE_SELECTOR; // default is 18 pt
@property (assign, nonatomic) CGFloat ringNoTextRadius UI_APPEARANCE_SELECTOR; // default is 24 pt
@property (assign, nonatomic) CGFloat cornerRadius UI_APPEARANCE_SELECTOR; // default is 14 pt
@property (strong, nonatomic, nonnull) UIFont *font UI_APPEARANCE_SELECTOR; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
@property (strong, nonatomic, nonnull) UIColor *backgroundColor UI_APPEARANCE_SELECTOR; // default is [UIColor whiteColor]
@property (strong, nonatomic, nonnull) UIColor *foregroundColor UI_APPEARANCE_SELECTOR; // default is [UIColor blackColor]
@property (strong, nonatomic, nonnull) UIColor *backgroundLayerColor UI_APPEARANCE_SELECTOR;// default is [UIColor colorWithWhite:0 alpha:0.4]
@property (assign, nonatomic) CGSize imageViewSize UI_APPEARANCE_SELECTOR; // default is 28x28 pt
@property (assign, nonatomic) BOOL shouldTintImages UI_APPEARANCE_SELECTOR; // default is YES
@property (strong, nonatomic, nonnull) UIImage *infoImage UI_APPEARANCE_SELECTOR; // default is the bundled info image provided by Freepik
@property (strong, nonatomic, nonnull) UIImage *successImage UI_APPEARANCE_SELECTOR; // default is the bundled success image provided by Freepik
@property (strong, nonatomic, nonnull) UIImage *errorImage UI_APPEARANCE_SELECTOR; // default is the bundled error image provided by Freepik
@property (strong, nonatomic, nonnull) UIView *viewForExtension UI_APPEARANCE_SELECTOR; // default is nil, only used if #define SV_APP_EXTENSIONS is set
@property (assign, nonatomic) NSTimeInterval graceTimeInterval; // default is 0 seconds
@property (assign, nonatomic) NSTimeInterval minimumDismissTimeInterval; // default is 5.0 seconds
@property (assign, nonatomic) NSTimeInterval maximumDismissTimeInterval; // default is CGFLOAT_MAX
/// Represents the default style for the HUD.
/// @discussion Default: SVProgressHUDStyleAutomatic.
@property (assign, nonatomic) SVProgressHUDStyle defaultStyle UI_APPEARANCE_SELECTOR;
@property (assign, nonatomic) UIOffset offsetFromCenter UI_APPEARANCE_SELECTOR; // default is 0, 0
/// Represents the type of mask applied when the HUD is displayed.
/// @discussion Default: SVProgressHUDMaskTypeNone.
@property (assign, nonatomic) SVProgressHUDMaskType defaultMaskType UI_APPEARANCE_SELECTOR;
@property (assign, nonatomic) NSTimeInterval fadeInAnimationDuration UI_APPEARANCE_SELECTOR; // default is 0.15
@property (assign, nonatomic) NSTimeInterval fadeOutAnimationDuration UI_APPEARANCE_SELECTOR; // default is 0.15
/// Defines the animation type used when the HUD is displayed.
/// @discussion Default: SVProgressHUDAnimationTypeFlat.
@property (assign, nonatomic) SVProgressHUDAnimationType defaultAnimationType UI_APPEARANCE_SELECTOR;
@property (assign, nonatomic) UIWindowLevel maxSupportedWindowLevel; // default is UIWindowLevelNormal
/// The container view used for displaying the HUD. If nil, the default window level is used.
@property (strong, nonatomic, nullable) UIView *containerView;
@property (assign, nonatomic) BOOL hapticsEnabled; // default is NO
/// The minimum size for the HUD. Useful for maintaining a consistent size when the message might cause resizing.
/// @discussion Default: CGSizeZero.
@property (assign, nonatomic) CGSize minimumSize UI_APPEARANCE_SELECTOR;
/// Thickness of the ring shown in the HUD.
/// @discussion Default: 2 pt.
@property (assign, nonatomic) CGFloat ringThickness UI_APPEARANCE_SELECTOR;
/// Radius of the ring shown in the HUD when there's associated text.
/// @discussion Default: 18 pt.
@property (assign, nonatomic) CGFloat ringRadius UI_APPEARANCE_SELECTOR;
/// Radius of the ring shown in the HUD when there's no associated text.
/// @discussion Default: 24 pt.
@property (assign, nonatomic) CGFloat ringNoTextRadius UI_APPEARANCE_SELECTOR;
/// Corner radius of the HUD view.
/// @discussion Default: 14 pt.
@property (assign, nonatomic) CGFloat cornerRadius UI_APPEARANCE_SELECTOR;
/// Font used for text within the HUD.
/// @discussion Default: [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline].
@property (strong, nonatomic, nonnull) UIFont *font UI_APPEARANCE_SELECTOR;
/// Background color of the HUD.
/// @discussion Default: [UIColor whiteColor].
@property (strong, nonatomic, nonnull) UIColor *backgroundColor UI_APPEARANCE_SELECTOR;
/// Foreground color used for content in the HUD.
/// @discussion Default: [UIColor blackColor].
@property (strong, nonatomic, nonnull) UIColor *foregroundColor UI_APPEARANCE_SELECTOR;
/// Color for any foreground images in the HUD.
/// @discussion Default: same as foregroundColor.
@property (strong, nonatomic, nullable) UIColor *foregroundImageColor UI_APPEARANCE_SELECTOR;
/// Color for the background layer behind the HUD.
/// @discussion Default: [UIColor colorWithWhite:0 alpha:0.4].
@property (strong, nonatomic, nonnull) UIColor *backgroundLayerColor UI_APPEARANCE_SELECTOR;
/// Size of any images displayed within the HUD.
/// @discussion Default: 28x28 pt.
@property (assign, nonatomic) CGSize imageViewSize UI_APPEARANCE_SELECTOR;
/// Indicates whether images within the HUD should be tinted.
/// @discussion Default: YES.
@property (assign, nonatomic) BOOL shouldTintImages UI_APPEARANCE_SELECTOR;
/// The image displayed when showing informational messages.
/// @discussion Default: info.circle from SF Symbols (iOS 13+) or the bundled info image provided by Freepik.
@property (strong, nonatomic, nonnull) UIImage *infoImage UI_APPEARANCE_SELECTOR;
/// The image displayed when showing success messages.
/// @discussion Default: checkmark from SF Symbols (iOS 13+) or the bundled success image provided by Freepik.
@property (strong, nonatomic, nonnull) UIImage *successImage UI_APPEARANCE_SELECTOR;
/// The image displayed when showing error messages.
/// @discussion Default: xmark from SF Symbols (iOS 13+) or the bundled error image provided by Freepik.
@property (strong, nonatomic, nonnull) UIImage *errorImage UI_APPEARANCE_SELECTOR;
/// A specific view for extensions. This property is only used if #define SV_APP_EXTENSIONS is set.
/// @discussion Default: nil.
@property (strong, nonatomic, nonnull) UIView *viewForExtension UI_APPEARANCE_SELECTOR;
/// The interval in seconds to wait before displaying the HUD. If the HUD is displayed before this time elapses, this timer is reset.
/// @discussion Default: 0 seconds.
@property (assign, nonatomic) NSTimeInterval graceTimeInterval;
/// The minimum amount of time in seconds the HUD will display.
/// @discussion Default: 5.0 seconds.
@property (assign, nonatomic) NSTimeInterval minimumDismissTimeInterval;
/// The maximum amount of time in seconds the HUD will display.
/// @discussion Default: CGFLOAT_MAX.
@property (assign, nonatomic) NSTimeInterval maximumDismissTimeInterval;
/// Offset from the center position, can be used to adjust the HUD position.
/// @discussion Default: 0, 0.
@property (assign, nonatomic) UIOffset offsetFromCenter UI_APPEARANCE_SELECTOR;
/// Duration of the fade-in animation when showing the HUD.
/// @discussion Default: 0.15.
@property (assign, nonatomic) NSTimeInterval fadeInAnimationDuration UI_APPEARANCE_SELECTOR;
/// Duration of the fade-out animation when hiding the HUD.
/// @discussion Default: 0.15.
@property (assign, nonatomic) NSTimeInterval fadeOutAnimationDuration UI_APPEARANCE_SELECTOR;
/// The maximum window level on which the HUD can be displayed.
/// @discussion Default: UIWindowLevelNormal.
@property (assign, nonatomic) UIWindowLevel maxSupportedWindowLevel;
/// Indicates if haptic feedback should be used.
/// @discussion Default: NO.
@property (assign, nonatomic) BOOL hapticsEnabled;
/// Indicates if motion effects should be applied to the HUD.
/// @discussion Default: YES.
@property (assign, nonatomic) BOOL motionEffectEnabled;
@property (class, strong, nonatomic, readonly, nonnull) NSBundle *imageBundle;
/// Sets the default style for the HUD.
/// @param style The desired style for the HUD.
+ (void)setDefaultStyle:(SVProgressHUDStyle)style;
/// Sets the default mask type for the HUD.
/// @param maskType The mask type to apply.
+ (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType;
/// Sets the default animation type for the HUD.
/// @param type The desired animation type.
+ (void)setDefaultAnimationType:(SVProgressHUDAnimationType)type;
/// Sets the container view for the HUD.
/// @param containerView The view to contain the HUD.
+ (void)setContainerView:(nullable UIView*)containerView;
/// Sets the minimum size for the HUD.
/// @param minimumSize The minimum size for the HUD.
+ (void)setMinimumSize:(CGSize)minimumSize;
/// Sets the ring thickness for the HUD.
/// @param ringThickness Thickness of the ring.
+ (void)setRingThickness:(CGFloat)ringThickness;
/// Sets the ring radius for the HUD.
/// @param radius Radius of the ring.
+ (void)setRingRadius:(CGFloat)radius;
/// Sets the no text ring radius for the HUD.
/// @param radius Radius of the ring when no text is displayed.
+ (void)setRingNoTextRadius:(CGFloat)radius;
/// Sets the corner radius for the HUD.
/// @param cornerRadius Desired corner radius.
+ (void)setCornerRadius:(CGFloat)cornerRadius;
/// Sets the border color for the HUD.
/// @param color Desired border color.
+ (void)setBorderColor:(nonnull UIColor*)color;
/// Sets the border width for the HUD.
/// @param width Desired border width.
+ (void)setBorderWidth:(CGFloat)width;
/// Sets the font for the HUD's text.
/// @param font Desired font for the text.
+ (void)setFont:(nonnull UIFont*)font;
/// Sets the foreground color for the HUD.
/// @param color Desired foreground color.
/// @discussion These implicitly set the HUD's style to `SVProgressHUDStyleCustom`.
+ (void)setForegroundColor:(nonnull UIColor*)color;
/// Sets the foreground image color for the HUD.
/// @param color Desired color for the image.
/// @discussion These implicitly set the HUD's style to `SVProgressHUDStyleCustom`.
+ (void)setForegroundImageColor:(nullable UIColor*)color;
/// Sets the background color for the HUD.
/// @param color Desired background color.
/// @discussion These implicitly set the HUD's style to `SVProgressHUDStyleCustom`.
+ (void)setBackgroundColor:(nonnull UIColor*)color;
/// Sets a custom blur effect for the HUD view.
/// @param blurEffect Desired blur effect.
/// @discussion These implicitly set the HUD's style to `SVProgressHUDStyleCustom`.
+ (void)setHudViewCustomBlurEffect:(nullable UIBlurEffect*)blurEffect;
/// Sets the background layer color for the HUD.
/// @param color Desired color for the background layer.
+ (void)setBackgroundLayerColor:(nonnull UIColor*)color;
/// Sets the size for the HUD's image view.
/// @param size Desired size for the image view.
+ (void)setImageViewSize:(CGSize)size;
/// Determines if images should be tinted in the HUD.
/// @param shouldTintImages Whether images should be tinted.
+ (void)setShouldTintImages:(BOOL)shouldTintImages;
/// Sets the info image for the HUD.
/// @param image The desired info image.
+ (void)setInfoImage:(nonnull UIImage*)image;
/// Sets the success image for the HUD.
/// @param image The desired success image.
+ (void)setSuccessImage:(nonnull UIImage*)image;
/// Sets the error image for the HUD.
/// @param image The desired error image.
+ (void)setErrorImage:(nonnull UIImage*)image;
/// Sets the view for extensions.
/// @param view The desired view for extensions.
+ (void)setViewForExtension:(nonnull UIView*)view;
/// Sets the grace time interval for the HUD.
/// @param interval Desired grace time interval.
+ (void)setGraceTimeInterval:(NSTimeInterval)interval;
/// Sets the minimum dismiss time interval.
/// @param interval The minimum time interval, in seconds, that the HUD should be displayed.
+ (void)setMinimumDismissTimeInterval:(NSTimeInterval)interval;
/// Sets the maximum dismiss time interval.
/// @param interval The maximum time interval, in seconds, that the HUD should be displayed.
+ (void)setMaximumDismissTimeInterval:(NSTimeInterval)interval;
/// Sets the fade-in animation duration.
/// @param duration The duration, in seconds, for the fade-in animation.
+ (void)setFadeInAnimationDuration:(NSTimeInterval)duration;
/// Sets the fade-out animation duration.
/// @param duration The duration, in seconds, for the fade-out animation.
+ (void)setFadeOutAnimationDuration:(NSTimeInterval)duration;
/// Sets the max supported window level.
/// @param windowLevel The UIWindowLevel to which the HUD should be displayed.
+ (void)setMaxSupportedWindowLevel:(UIWindowLevel)windowLevel;
/// Determines if haptics are enabled.
/// @param hapticsEnabled A boolean that determines if haptic feedback is enabled.
+ (void)setHapticsEnabled:(BOOL)hapticsEnabled;
/// Determines if motion effect is enabled.
/// @param motionEffectEnabled A boolean that determines if motion effects are enabled.
+ (void)setMotionEffectEnabled:(BOOL)motionEffectEnabled;
+ (void)setDefaultStyle:(SVProgressHUDStyle)style; // default is SVProgressHUDStyleLight
+ (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType; // default is SVProgressHUDMaskTypeNone
+ (void)setDefaultAnimationType:(SVProgressHUDAnimationType)type; // default is SVProgressHUDAnimationTypeFlat
+ (void)setContainerView:(nullable UIView*)containerView; // default is window level
+ (void)setMinimumSize:(CGSize)minimumSize; // default is CGSizeZero, can be used to avoid resizing for a larger message
+ (void)setRingThickness:(CGFloat)ringThickness; // default is 2 pt
+ (void)setRingRadius:(CGFloat)radius; // default is 18 pt
+ (void)setRingNoTextRadius:(CGFloat)radius; // default is 24 pt
+ (void)setCornerRadius:(CGFloat)cornerRadius; // default is 14 pt
+ (void)setBorderColor:(nonnull UIColor*)color; // default is nil
+ (void)setBorderWidth:(CGFloat)width; // default is 0
+ (void)setFont:(nonnull UIFont*)font; // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
+ (void)setForegroundColor:(nonnull UIColor*)color; // default is [UIColor blackColor], only used for SVProgressHUDStyleCustom
+ (void)setBackgroundColor:(nonnull UIColor*)color; // default is [UIColor whiteColor], only used for SVProgressHUDStyleCustom
+ (void)setBackgroundLayerColor:(nonnull UIColor*)color; // default is [UIColor colorWithWhite:0 alpha:0.5], only used for SVProgressHUDMaskTypeCustom
+ (void)setImageViewSize:(CGSize)size; // default is 28x28 pt
+ (void)setShouldTintImages:(BOOL)shouldTintImages; // default is YES
+ (void)setInfoImage:(nonnull UIImage*)image; // default is the bundled info image provided by Freepik
+ (void)setSuccessImage:(nonnull UIImage*)image; // default is the bundled success image provided by Freepik
+ (void)setErrorImage:(nonnull UIImage*)image; // default is the bundled error image provided by Freepik
+ (void)setViewForExtension:(nonnull UIView*)view; // default is nil, only used if #define SV_APP_EXTENSIONS is set
+ (void)setGraceTimeInterval:(NSTimeInterval)interval; // default is 0 seconds
+ (void)setMinimumDismissTimeInterval:(NSTimeInterval)interval; // default is 5.0 seconds
+ (void)setMaximumDismissTimeInterval:(NSTimeInterval)interval; // default is infinite
+ (void)setFadeInAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds
+ (void)setFadeOutAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds
+ (void)setMaxSupportedWindowLevel:(UIWindowLevel)windowLevel; // default is UIWindowLevelNormal
+ (void)setHapticsEnabled:(BOOL)hapticsEnabled; // default is NO
#pragma mark - Show Methods
/// Shows the HUD without any additional status message.
+ (void)show;
+ (void)showWithMaskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use show and setDefaultMaskType: instead.")));
/// Shows the HUD with a provided status message.
/// @param status The message to be displayed alongside the HUD.
+ (void)showWithStatus:(nullable NSString*)status;
+ (void)showWithStatus:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showWithStatus: and setDefaultMaskType: instead.")));
/// Display methods to show progress on the HUD.
/// Shows the HUD with a progress indicator.
/// @param progress A float value between 0.0 and 1.0 indicating the progress.
+ (void)showProgress:(float)progress;
+ (void)showProgress:(float)progress maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showProgress: and setDefaultMaskType: instead.")));
/// Shows the HUD with a progress indicator and a provided status message.
/// @param progress A float value between 0.0 and 1.0 indicating the progress.
/// @param status The message to be displayed alongside the progress indicator.
+ (void)showProgress:(float)progress status:(nullable NSString*)status;
+ (void)showProgress:(float)progress status:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showProgress:status: and setDefaultMaskType: instead.")));
+ (void)setStatus:(nullable NSString*)status; // change the HUD loading status while it's showing
/// Updates the current status of the loading HUD.
/// @param status The new status message to update the HUD with.
+ (void)setStatus:(nullable NSString*)status;
// stops the activity indicator, shows a glyph + status, and dismisses the HUD a little bit later
/// Shows an info status with the provided message.
/// @param status The info message to be displayed.
+ (void)showInfoWithStatus:(nullable NSString*)status;
+ (void)showInfoWithStatus:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showInfoWithStatus: and setDefaultMaskType: instead.")));
/// Shows a success status with the provided message.
/// @param status The success message to be displayed.
+ (void)showSuccessWithStatus:(nullable NSString*)status;
+ (void)showSuccessWithStatus:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showSuccessWithStatus: and setDefaultMaskType: instead.")));
/// Shows an error status with the provided message.
/// @param status The error message to be displayed.
+ (void)showErrorWithStatus:(nullable NSString*)status;
+ (void)showErrorWithStatus:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showErrorWithStatus: and setDefaultMaskType: instead.")));
// shows a image + status, use white PNGs with the imageViewSize (default is 28x28 pt)
/// Shows a custom image with the provided status message.
/// @param image The custom image to be displayed.
/// @param status The message to accompany the custom image.
+ (void)showImage:(nonnull UIImage*)image status:(nullable NSString*)status;
+ (void)showImage:(nonnull UIImage*)image status:(nullable NSString*)status maskType:(SVProgressHUDMaskType)maskType __attribute__((deprecated("Use showImage:status: and setDefaultMaskType: instead.")));
/// Sets the offset from the center for the HUD.
/// @param offset The UIOffset value indicating how much the HUD should be offset from its center position.
+ (void)setOffsetFromCenter:(UIOffset)offset;
/// Resets the offset to center the HUD.
+ (void)resetOffsetFromCenter;
+ (void)popActivity; // decrease activity count, if activity count == 0 the HUD is dismissed
/// Decreases the activity count, dismissing the HUD if count reaches 0.
+ (void)popActivity;
/// Dismisses the HUD immediately.
+ (void)dismiss;
/// Dismisses the HUD and triggers a completion block.
/// @param completion A block that gets executed after the HUD is dismissed.
+ (void)dismissWithCompletion:(nullable SVProgressHUDDismissCompletion)completion;
/// Dismisses the HUD after a specified delay.
/// @param delay The time in seconds after which the HUD should be dismissed.
+ (void)dismissWithDelay:(NSTimeInterval)delay;
/// Dismisses the HUD after a specified delay and triggers a completion block.
/// @param delay The time in seconds after which the HUD should be dismissed.
/// @param completion A block that gets executed after the HUD is dismissed.
+ (void)dismissWithDelay:(NSTimeInterval)delay completion:(nullable SVProgressHUDDismissCompletion)completion;
/// Checks if the HUD is currently visible.
/// @return A boolean value indicating whether the HUD is visible.
+ (BOOL)isVisible;
/// Calculates the display duration based on a given string's length.
/// @param string The string whose length determines the display duration.
/// @return A time interval representing the display duration.
+ (NSTimeInterval)displayDurationForString:(nullable NSString*)string;
@end

View File

@@ -2,7 +2,7 @@
// SVProgressHUD.h
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2011-2018 Sam Vermette and contributors. All rights reserved.
// Copyright (c) 2011-2023 Sam Vermette and contributors. All rights reserved.
//
#if !__has_feature(objc_arc)
@@ -40,6 +40,7 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
@property (nonatomic, strong) UIView *backgroundView;
@property (nonatomic, strong) SVRadialGradientLayer *backgroundRadialGradientLayer;
@property (nonatomic, strong) UIVisualEffectView *hudView;
@property (nonatomic, strong) UIBlurEffect *hudViewCustomBlurEffect;
@property (nonatomic, strong) UILabel *statusLabel;
@property (nonatomic, strong) UIImageView *imageView;
@@ -53,8 +54,8 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
@property (nonatomic, readonly) CGFloat visibleKeyboardHeight;
@property (nonatomic, readonly) UIWindow *frontWindow;
#if TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
@property (nonatomic, strong) UINotificationFeedbackGenerator *hapticGenerator NS_AVAILABLE_IOS(10_0);
#if TARGET_OS_IOS
@property (nonatomic, strong) UINotificationFeedbackGenerator *hapticGenerator;
#endif
@end
@@ -68,13 +69,41 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
static SVProgressHUD *sharedView;
#if !defined(SV_APP_EXTENSIONS)
dispatch_once(&once, ^{ sharedView = [[self alloc] initWithFrame:[[[UIApplication sharedApplication] delegate] window].bounds]; });
dispatch_once(&once, ^{ sharedView = [[self alloc] initWithFrame:[SVProgressHUD mainWindow].bounds]; });
#else
dispatch_once(&once, ^{ sharedView = [[self alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; });
#endif
return sharedView;
}
+ (UIWindow *)mainWindow {
if (@available(iOS 13.0, *)) {
for (UIWindowScene* windowScene in [UIApplication sharedApplication].connectedScenes) {
if (windowScene.activationState == UISceneActivationStateForegroundActive) {
return windowScene.windows.firstObject;
}
}
// If a window has not been returned by now, the first scene's window is returned (regardless of activationState).
UIWindowScene *windowScene = (UIWindowScene *)[[UIApplication sharedApplication].connectedScenes allObjects].firstObject;
return windowScene.windows.firstObject;
} else {
#if TARGET_OS_IOS
return [[[UIApplication sharedApplication] delegate] window];
#else
return [UIApplication sharedApplication].keyWindow;
#endif
}
}
+ (NSBundle *)imageBundle {
#if defined(SWIFTPM_MODULE_BUNDLE)
NSBundle *bundle = SWIFTPM_MODULE_BUNDLE;
#else
NSBundle *bundle = [NSBundle bundleForClass:[SVProgressHUD class]];
#endif
NSURL *url = [bundle URLForResource:@"SVProgressHUD" withExtension:@"bundle"];
return [NSBundle bundleWithURL:url];
}
#pragma mark - Setters
@@ -135,11 +164,21 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
[self setDefaultStyle:SVProgressHUDStyleCustom];
}
+ (void)setForegroundImageColor:(UIColor *)color {
[self sharedView].foregroundImageColor = color;
[self setDefaultStyle:SVProgressHUDStyleCustom];
}
+ (void)setBackgroundColor:(UIColor*)color {
[self sharedView].backgroundColor = color;
[self setDefaultStyle:SVProgressHUDStyleCustom];
}
+ (void)setHudViewCustomBlurEffect:(UIBlurEffect*)blurEffect {
[self sharedView].hudViewCustomBlurEffect = blurEffect;
[self setDefaultStyle:SVProgressHUDStyleCustom];
}
+ (void)setBackgroundLayerColor:(UIColor*)color {
[self sharedView].backgroundLayerColor = color;
}
@@ -196,125 +235,58 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
[self sharedView].hapticsEnabled = hapticsEnabled;
}
+ (void)setMotionEffectEnabled:(BOOL)motionEffectEnabled {
[self sharedView].motionEffectEnabled = motionEffectEnabled;
}
#pragma mark - Show Methods
+ (void)show {
[self showWithStatus:nil];
}
+ (void)showWithMaskType:(SVProgressHUDMaskType)maskType {
SVProgressHUDMaskType existingMaskType = [self sharedView].defaultMaskType;
[self setDefaultMaskType:maskType];
[self show];
[self setDefaultMaskType:existingMaskType];
}
+ (void)showWithStatus:(NSString*)status {
[self showProgress:SVProgressHUDUndefinedProgress status:status];
}
+ (void)showWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType {
SVProgressHUDMaskType existingMaskType = [self sharedView].defaultMaskType;
[self setDefaultMaskType:maskType];
[self showWithStatus:status];
[self setDefaultMaskType:existingMaskType];
}
+ (void)showProgress:(float)progress {
[self showProgress:progress status:nil];
}
+ (void)showProgress:(float)progress maskType:(SVProgressHUDMaskType)maskType {
SVProgressHUDMaskType existingMaskType = [self sharedView].defaultMaskType;
[self setDefaultMaskType:maskType];
[self showProgress:progress];
[self setDefaultMaskType:existingMaskType];
}
+ (void)showProgress:(float)progress status:(NSString*)status {
[[self sharedView] showProgress:progress status:status];
}
+ (void)showProgress:(float)progress status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType {
SVProgressHUDMaskType existingMaskType = [self sharedView].defaultMaskType;
[self setDefaultMaskType:maskType];
[self showProgress:progress status:status];
[self setDefaultMaskType:existingMaskType];
}
#pragma mark - Show, then automatically dismiss methods
+ (void)showInfoWithStatus:(NSString*)status {
[self showImage:[self sharedView].infoImage status:status];
#if TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
if (@available(iOS 10.0, *)) {
dispatch_async(dispatch_get_main_queue(), ^{
[[self sharedView].hapticGenerator notificationOccurred:UINotificationFeedbackTypeWarning];
});
}
#if TARGET_OS_IOS
dispatch_async(dispatch_get_main_queue(), ^{
[[self sharedView].hapticGenerator notificationOccurred:UINotificationFeedbackTypeWarning];
});
#endif
}
+ (void)showInfoWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType {
SVProgressHUDMaskType existingMaskType = [self sharedView].defaultMaskType;
[self setDefaultMaskType:maskType];
[self showInfoWithStatus:status];
[self setDefaultMaskType:existingMaskType];
}
+ (void)showSuccessWithStatus:(NSString*)status {
[self showImage:[self sharedView].successImage status:status];
#if TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
if (@available(iOS 10, *)) {
dispatch_async(dispatch_get_main_queue(), ^{
[[self sharedView].hapticGenerator notificationOccurred:UINotificationFeedbackTypeSuccess];
});
}
#endif
}
+ (void)showSuccessWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType {
SVProgressHUDMaskType existingMaskType = [self sharedView].defaultMaskType;
[self setDefaultMaskType:maskType];
[self showSuccessWithStatus:status];
[self setDefaultMaskType:existingMaskType];
#if TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
if (@available(iOS 10.0, *)) {
dispatch_async(dispatch_get_main_queue(), ^{
[[self sharedView].hapticGenerator notificationOccurred:UINotificationFeedbackTypeSuccess];
});
}
#if TARGET_OS_IOS
dispatch_async(dispatch_get_main_queue(), ^{
[[self sharedView].hapticGenerator notificationOccurred:UINotificationFeedbackTypeSuccess];
});
#endif
}
+ (void)showErrorWithStatus:(NSString*)status {
[self showImage:[self sharedView].errorImage status:status];
#if TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
if (@available(iOS 10.0, *)) {
dispatch_async(dispatch_get_main_queue(), ^{
[[self sharedView].hapticGenerator notificationOccurred:UINotificationFeedbackTypeError];
});
}
#endif
}
+ (void)showErrorWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType {
SVProgressHUDMaskType existingMaskType = [self sharedView].defaultMaskType;
[self setDefaultMaskType:maskType];
[self showErrorWithStatus:status];
[self setDefaultMaskType:existingMaskType];
#if TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
if (@available(iOS 10.0, *)) {
dispatch_async(dispatch_get_main_queue(), ^{
[[self sharedView].hapticGenerator notificationOccurred:UINotificationFeedbackTypeError];
});
}
#if TARGET_OS_IOS
dispatch_async(dispatch_get_main_queue(), ^{
[[self sharedView].hapticGenerator notificationOccurred:UINotificationFeedbackTypeError];
});
#endif
}
@@ -323,13 +295,6 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
[[self sharedView] showImage:image status:status duration:displayInterval];
}
+ (void)showImage:(UIImage*)image status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType {
SVProgressHUDMaskType existingMaskType = [self sharedView].defaultMaskType;
[self setDefaultMaskType:maskType];
[self showImage:image status:status];
[self setDefaultMaskType:existingMaskType];
}
#pragma mark - Dismiss Methods
@@ -392,7 +357,7 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
// Set default values
_defaultMaskType = SVProgressHUDMaskTypeNone;
_defaultStyle = SVProgressHUDStyleLight;
_defaultStyle = SVProgressHUDStyleAutomatic;
_defaultAnimationType = SVProgressHUDAnimationTypeFlat;
_minimumSize = CGSizeZero;
_font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
@@ -400,14 +365,18 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
_imageViewSize = CGSizeMake(28.0f, 28.0f);
_shouldTintImages = YES;
NSBundle *bundle = [NSBundle bundleForClass:[SVProgressHUD class]];
NSURL *url = [bundle URLForResource:@"SVProgressHUD" withExtension:@"bundle"];
NSBundle *imageBundle = [NSBundle bundleWithURL:url];
NSBundle *imageBundle = [SVProgressHUD imageBundle];
if (@available(iOS 13.0, *)) {
_infoImage = [UIImage systemImageNamed:@"info.circle"];
_successImage = [UIImage systemImageNamed:@"checkmark"];
_errorImage = [UIImage systemImageNamed:@"xmark"];
} else {
_infoImage = [UIImage imageWithContentsOfFile:[imageBundle pathForResource:@"info" ofType:@"png"]];
_successImage = [UIImage imageWithContentsOfFile:[imageBundle pathForResource:@"success" ofType:@"png"]];
_errorImage = [UIImage imageWithContentsOfFile:[imageBundle pathForResource:@"error" ofType:@"png"]];
}
_infoImage = [UIImage imageWithContentsOfFile:[imageBundle pathForResource:@"info" ofType:@"png"]];
_successImage = [UIImage imageWithContentsOfFile:[imageBundle pathForResource:@"success" ofType:@"png"]];
_errorImage = [UIImage imageWithContentsOfFile:[imageBundle pathForResource:@"error" ofType:@"png"]];
_ringThickness = 2.0f;
_ringRadius = 18.0f;
_ringNoTextRadius = 24.0f;
@@ -424,6 +393,7 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
_maxSupportedWindowLevel = UIWindowLevelNormal;
_hapticsEnabled = NO;
_motionEffectEnabled = YES;
// Accessibility support
self.accessibilityIdentifier = @"SVProgressHUD";
@@ -436,7 +406,7 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
- (void)updateHUDFrame {
// Check if an image or progress ring is displayed
BOOL imageUsed = (self.imageView.image) && !(self.imageView.hidden);
BOOL imageUsed = (self.imageView.image) && !(self.imageView.hidden) && (self.imageViewSize.height > 0 && self.imageViewSize.width > 0);
BOOL progressUsed = self.imageView.hidden;
// Calculate size of string
@@ -513,8 +483,9 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
#if TARGET_OS_IOS
- (void)updateMotionEffectForOrientation:(UIInterfaceOrientation)orientation {
UIInterpolatingMotionEffectType xMotionEffectType = UIInterfaceOrientationIsPortrait(orientation) ? UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis : UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis;
UIInterpolatingMotionEffectType yMotionEffectType = UIInterfaceOrientationIsPortrait(orientation) ? UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis : UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis;
bool isPortrait = UIInterfaceOrientationIsPortrait(orientation);
UIInterpolatingMotionEffectType xMotionEffectType = isPortrait ? UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis : UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis;
UIInterpolatingMotionEffectType yMotionEffectType = isPortrait ? UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis : UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis;
[self updateMotionEffectForXMotionEffectType:xMotionEffectType yMotionEffectType:yMotionEffectType];
}
#endif
@@ -635,10 +606,10 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
double animationDuration = 0.0;
#if !defined(SV_APP_EXTENSIONS) && TARGET_OS_IOS
self.frame = [[[UIApplication sharedApplication] delegate] window].bounds;
self.frame = [SVProgressHUD mainWindow].bounds;
UIInterfaceOrientation orientation = UIApplication.sharedApplication.statusBarOrientation;
#elif !defined(SV_APP_EXTENSIONS) && !TARGET_OS_IOS
self.frame= [UIApplication sharedApplication].keyWindow.bounds;
self.frame = [SVProgressHUD mainWindow].bounds;
#else
if (self.viewForExtension) {
self.frame = self.viewForExtension.frame;
@@ -678,12 +649,14 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
CGRect statusBarFrame = CGRectZero;
#endif
if (_motionEffectEnabled) {
#if TARGET_OS_IOS
// Update the motion effects in regard to orientation
[self updateMotionEffectForOrientation:orientation];
// Update the motion effects in regard to orientation
[self updateMotionEffectForOrientation:orientation];
#else
[self updateMotionEffectForXMotionEffectType:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis yMotionEffectType:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
[self updateMotionEffectForXMotionEffectType:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis yMotionEffectType:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
#endif
}
// Calculate available height for display
CGFloat activeHeight = CGRectGetHeight(orientationFrame);
@@ -813,10 +786,8 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
}
// Tell the Haptics Generator to prepare for feedback, which may come soon
#if TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
if (@available(iOS 10.0, *)) {
[strongSelf.hapticGenerator prepare];
}
#if TARGET_OS_IOS
[strongSelf.hapticGenerator prepare];
#endif
}
}];
@@ -843,8 +814,10 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
if (self.shouldTintImages) {
if (image.renderingMode != UIImageRenderingModeAlwaysTemplate) {
strongSelf.imageView.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
} else {
strongSelf.imageView.image = image;
}
strongSelf.imageView.tintColor = strongSelf.foregroundColorForStyle;;
strongSelf.imageView.tintColor = strongSelf.foregroundImageColorForStyle;
} else {
strongSelf.imageView.image = image;
}
@@ -872,14 +845,19 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
[self positionHUD:nil];
// Update accessibility as well as user interaction
// \n cause to read text twice so remove "\n" new line character before setting up accessiblity label
NSString *accessibilityString = [[self.statusLabel.text componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] componentsJoinedByString:@" "];
if(self.defaultMaskType != SVProgressHUDMaskTypeNone) {
self.controlView.userInteractionEnabled = YES;
self.accessibilityLabel = self.statusLabel.text ?: NSLocalizedString(@"Loading", nil);
self.accessibilityLabel = accessibilityString ?: NSLocalizedString(@"Loading", nil);
self.isAccessibilityElement = YES;
self.controlView.accessibilityViewIsModal = YES;
} else {
self.controlView.userInteractionEnabled = NO;
self.hudView.accessibilityLabel = self.statusLabel.text ?: NSLocalizedString(@"Loading", nil);
self.hudView.accessibilityLabel = accessibilityString ?: NSLocalizedString(@"Loading", nil);
self.isAccessibilityElement = NO;
self.hudView.isAccessibilityElement = YES;
self.controlView.accessibilityViewIsModal = NO;
}
// Get duration
@@ -892,8 +870,8 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
object:self
userInfo:[self notificationUserInfo]];
// Shrink HUD to to make a nice appear / pop up animation
self.hudView.transform = self.hudView.transform = CGAffineTransformScale(self.hudView.transform, 1/1.5f, 1/1.5f);
// Zoom HUD a little to to make a nice appear / pop up animation
self.hudView.transform = self.hudView.transform = CGAffineTransformScale(self.hudView.transform, 1.3f, 1.3f);
__block void (^animationsBlock)(void) = ^{
// Zoom HUD a little to make a nice appear / pop up animation
@@ -969,8 +947,6 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
__strong SVProgressHUD *strongSelf = weakSelf;
if(strongSelf){
// Stop timer
strongSelf.graceTimer = nil;
// Post notification to inform user
[[NSNotificationCenter defaultCenter] postNotificationName:SVProgressHUDWillDisappearNotification
@@ -1013,7 +989,7 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
// Tell the rootViewController to update the StatusBar appearance
#if !defined(SV_APP_EXTENSIONS) && TARGET_OS_IOS
UIViewController *rootController = [[UIApplication sharedApplication] keyWindow].rootViewController;
UIViewController *rootController = [SVProgressHUD mainWindow].rootViewController;
[rootController setNeedsStatusBarAppearanceUpdate];
#endif
@@ -1031,6 +1007,10 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
dispatch_time_t dipatchTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC));
dispatch_after(dipatchTime, dispatch_get_main_queue(), ^{
// Stop timer
strongSelf.graceTimer = nil;
if (strongSelf.fadeOutAnimationDuration > 0) {
// Animate appearance
[UIView animateWithDuration:strongSelf.fadeOutAnimationDuration
@@ -1071,7 +1051,7 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
// Update styling
SVIndefiniteAnimatedView *indefiniteAnimatedView = (SVIndefiniteAnimatedView*)_indefiniteAnimatedView;
indefiniteAnimatedView.strokeColor = self.foregroundColorForStyle;
indefiniteAnimatedView.strokeColor = self.foregroundImageColorForStyle;
indefiniteAnimatedView.strokeThickness = self.ringThickness;
indefiniteAnimatedView.radius = self.statusLabel.text ? self.ringRadius : self.ringNoTextRadius;
} else {
@@ -1087,7 +1067,7 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
// Update styling
UIActivityIndicatorView *activityIndicatorView = (UIActivityIndicatorView*)_indefiniteAnimatedView;
activityIndicatorView.color = self.foregroundColorForStyle;
activityIndicatorView.color = self.foregroundImageColorForStyle;
}
[_indefiniteAnimatedView sizeToFit];
@@ -1100,7 +1080,7 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
}
// Update styling
_ringView.strokeColor = self.foregroundColorForStyle;
_ringView.strokeColor = self.foregroundImageColorForStyle;
_ringView.strokeThickness = self.ringThickness;
_ringView.radius = self.statusLabel.text ? self.ringRadius : self.ringNoTextRadius;
@@ -1114,7 +1094,7 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
}
// Update styling
_backgroundRingView.strokeColor = [self.foregroundColorForStyle colorWithAlphaComponent:0.1f];
_backgroundRingView.strokeColor = [self.foregroundImageColorForStyle colorWithAlphaComponent:0.1f];
_backgroundRingView.strokeThickness = self.ringThickness;
_backgroundRingView.radius = self.statusLabel.text ? self.ringRadius : self.ringNoTextRadius;
@@ -1162,19 +1142,31 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
}
- (UIColor*)foregroundColorForStyle {
if(self.defaultStyle == SVProgressHUDStyleLight) {
SVProgressHUDStyle style = [self defaultStyleResolvingAutomatic];
if(style == SVProgressHUDStyleLight) {
return [UIColor blackColor];
} else if(self.defaultStyle == SVProgressHUDStyleDark) {
} else if(style == SVProgressHUDStyleDark) {
return [UIColor whiteColor];
} else {
return self.foregroundColor;
}
}
- (UIColor*)foregroundImageColorForStyle {
if (self.foregroundImageColor) {
return self.foregroundImageColor;
} else {
return [self foregroundColorForStyle];
}
}
- (UIColor*)backgroundColorForStyle {
if(self.defaultStyle == SVProgressHUDStyleLight) {
SVProgressHUDStyle style = [self defaultStyleResolvingAutomatic];
if(style == SVProgressHUDStyleLight) {
return [UIColor whiteColor];
} else if(self.defaultStyle == SVProgressHUDStyleDark) {
} else if(style == SVProgressHUDStyleDark) {
return [UIColor blackColor];
} else {
return self.backgroundColor;
@@ -1190,10 +1182,9 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
[_controlView addTarget:self action:@selector(controlViewDidReceiveTouchEvent:forEvent:) forControlEvents:UIControlEventTouchDown];
}
// Update frames
// Update frame
#if !defined(SV_APP_EXTENSIONS)
CGRect windowBounds = [[[UIApplication sharedApplication] delegate] window].bounds;
_controlView.frame = windowBounds;
_controlView.frame = [SVProgressHUD mainWindow].bounds;
#else
_controlView.frame = [UIScreen mainScreen].bounds;
#endif
@@ -1269,6 +1260,7 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
_statusLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_statusLabel.backgroundColor = [UIColor clearColor];
_statusLabel.adjustsFontSizeToFitWidth = YES;
_statusLabel.adjustsFontForContentSizeCategory = YES;
_statusLabel.textAlignment = NSTextAlignmentCenter;
_statusLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
_statusLabel.numberOfLines = 0;
@@ -1302,7 +1294,15 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
#pragma mark - Helper
- (SVProgressHUDStyle) defaultStyleResolvingAutomatic {
if(self.defaultStyle == SVProgressHUDStyleAutomatic) {
return self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark ? SVProgressHUDStyleDark : SVProgressHUDStyleLight;
}
return self.defaultStyle;
}
- (CGFloat)visibleKeyboardHeight {
#if !defined(SV_APP_EXTENSIONS)
UIWindow *keyboardWindow = nil;
@@ -1356,7 +1356,17 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
- (void)fadeInEffects {
if(self.defaultStyle != SVProgressHUDStyleCustom) {
// Add blur effect
UIBlurEffectStyle blurEffectStyle = self.defaultStyle == SVProgressHUDStyleDark ? UIBlurEffectStyleDark : UIBlurEffectStyleLight;
UIBlurEffectStyle blurEffectStyle;
#if TARGET_OS_IOS
if (@available(iOS 13.0, *)) {
blurEffectStyle = [self defaultStyleResolvingAutomatic] == SVProgressHUDStyleLight ? UIBlurEffectStyleSystemMaterial : UIBlurEffectStyleSystemMaterialDark;
} else {
blurEffectStyle = [self defaultStyleResolvingAutomatic] == SVProgressHUDStyleLight ? UIBlurEffectStyleLight : UIBlurEffectStyleDark;
}
#else
blurEffectStyle = [self defaultStyleResolvingAutomatic] == SVProgressHUDStyleLight ? UIBlurEffectStyleLight : UIBlurEffectStyleDark;
#endif
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:blurEffectStyle];
self.hudView.effect = blurEffect;
@@ -1366,6 +1376,7 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
self.hudView.backgroundColor = [self.backgroundColorForStyle colorWithAlphaComponent:0.6f];
} else {
self.hudView.effect = self.hudViewCustomBlurEffect;
self.hudView.backgroundColor = self.backgroundColorForStyle;
}
@@ -1397,8 +1408,8 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
self.ringView.alpha = self.backgroundRingView.alpha = 0.0f;
}
#if TARGET_OS_IOS && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100000
- (UINotificationFeedbackGenerator *)hapticGenerator NS_AVAILABLE_IOS(10_0) {
#if TARGET_OS_IOS
- (UINotificationFeedbackGenerator *)hapticGenerator {
// Only return if haptics are enabled
if(!self.hapticsEnabled) {
return nil;
@@ -1458,6 +1469,10 @@ static const CGFloat SVProgressHUDLabelSpacing = 8.0f;
if (!_isInitializing) _foregroundColor = color;
}
- (void)setForegroundImageColor:(UIColor *)color {
if (!_isInitializing) _foregroundImageColor = color;
}
- (void)setBackgroundColor:(UIColor*)color {
if (!_isInitializing) _backgroundColor = color;
}

View File

@@ -2,7 +2,7 @@
// SVRadialGradientLayer.h
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2014-2018 Tobias Tiemerding. All rights reserved.
// Copyright (c) 2014-2023 Tobias Totzek and contributors. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>

View File

@@ -2,7 +2,7 @@
// SVRadialGradientLayer.m
// SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
//
// Copyright (c) 2014-2018 Tobias Tiemerding. All rights reserved.
// Copyright (c) 2014-2023 Tobias Totzek and contributors. All rights reserved.
//
#import "SVRadialGradientLayer.h"