Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Custom loading image view #865

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions Demo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand Down Expand Up @@ -97,10 +97,11 @@
</connections>
</segmentedControl>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="iAW-K3-Ahn">
<rect key="frame" x="252" y="497.5" width="107" height="29"/>
<rect key="frame" x="174" y="497.5" width="185" height="29"/>
<segments>
<segment title="Flat"/>
<segment title="Native"/>
<segment title="Custom"/>
</segments>
<connections>
<action selector="changeAnimationType:" destination="BYZ-38-t0r" eventType="valueChanged" id="1ZL-YJ-4lL"/>
Expand Down
Binary file added Demo/Classes/Resource.bundle/loading1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading10.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading10@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading10@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading11.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading11@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading11@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading12.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading12@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading12@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading13.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading13@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading13@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading14.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading14@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading14@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading15.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading15@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading15@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading16@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading16@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading17.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading17@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading17@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Demo/Classes/Resource.bundle/loading18.png
Binary file added Demo/Classes/Resource.bundle/loading18@2x.png
Binary file added Demo/Classes/Resource.bundle/loading18@3x.png
Binary file added Demo/Classes/Resource.bundle/loading1@2x.png
Binary file added Demo/Classes/Resource.bundle/loading1@3x.png
Binary file added Demo/Classes/Resource.bundle/loading2.png
Binary file added Demo/Classes/Resource.bundle/loading2@2x.png
Binary file added Demo/Classes/Resource.bundle/loading2@3x.png
Binary file added Demo/Classes/Resource.bundle/loading3.png
Binary file added Demo/Classes/Resource.bundle/loading3@2x.png
Binary file added Demo/Classes/Resource.bundle/loading3@3x.png
Binary file added Demo/Classes/Resource.bundle/loading4.png
Binary file added Demo/Classes/Resource.bundle/loading4@2x.png
Binary file added Demo/Classes/Resource.bundle/loading4@3x.png
Binary file added Demo/Classes/Resource.bundle/loading5.png
Binary file added Demo/Classes/Resource.bundle/loading5@2x.png
Binary file added Demo/Classes/Resource.bundle/loading5@3x.png
Binary file added Demo/Classes/Resource.bundle/loading6.png
Binary file added Demo/Classes/Resource.bundle/loading6@2x.png
Binary file added Demo/Classes/Resource.bundle/loading6@3x.png
Binary file added Demo/Classes/Resource.bundle/loading7.png
Binary file added Demo/Classes/Resource.bundle/loading7@2x.png
Binary file added Demo/Classes/Resource.bundle/loading7@3x.png
Binary file added Demo/Classes/Resource.bundle/loading8.png
Binary file added Demo/Classes/Resource.bundle/loading8@2x.png
Binary file added Demo/Classes/Resource.bundle/loading8@3x.png
Binary file added Demo/Classes/Resource.bundle/loading9.png
Binary file added Demo/Classes/Resource.bundle/loading9@2x.png
Binary file added Demo/Classes/Resource.bundle/loading9@3x.png
25 changes: 23 additions & 2 deletions Demo/Classes/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,38 @@ - (IBAction)changeStyle:(id)sender {
UISegmentedControl *segmentedControl = (UISegmentedControl*)sender;
if(segmentedControl.selectedSegmentIndex == 0){
[SVProgressHUD setDefaultStyle:SVProgressHUDStyleLight];
} else {
} else if (segmentedControl.selectedSegmentIndex == 1) {
[SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
} else {
[SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
}
}

- (IBAction)changeAnimationType:(id)sender {
UISegmentedControl *segmentedControl = (UISegmentedControl*)sender;
if(segmentedControl.selectedSegmentIndex == 0){
[SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeFlat];
} else {
} else if(segmentedControl.selectedSegmentIndex == 1){
[SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeNative];
} else {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 90, 90)];
NSBundle *bundle = [NSBundle bundleForClass:[SVProgressHUD class]];
NSURL *url = [bundle URLForResource:@"Resource" withExtension:@"bundle"];
NSBundle *imageBundle = [NSBundle bundleWithURL:url];
NSMutableArray *imageArray = [NSMutableArray array];
for (int i = 1; i <= 18; i++) {
NSString *fileNumber = [NSString stringWithFormat:@"%d", i];
NSString *fileName = [NSString stringWithFormat:@"%@%@",@"loading",fileNumber];
NSString *path = [imageBundle pathForResource: fileName ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:path];
[imageArray addObject: image];
}
imageView.animationImages = imageArray;
imageView.animationDuration = 1.5f;
imageView.animationRepeatCount = 0;
[imageView startAnimating];
[SVProgressHUD setLoadingImageView:imageView];
[SVProgressHUD setDefaultAnimationType:SVProgressHUDAnimationTypeCustom];
}
}

Expand Down
4 changes: 4 additions & 0 deletions Demo/SVProgressHUD.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
3CD078EA1A3B809500290D80 /* SVRadialGradientLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CD078E91A3B809500290D80 /* SVRadialGradientLayer.m */; };
3FF0384716633A330070E901 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3FF0384616633A330070E901 /* QuartzCore.framework */; };
63ADC4BC1364C1360060E45B /* SVProgressHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = 63ADC4BA1364C1360060E45B /* SVProgressHUD.m */; };
6EF44707200F9A45000B6E4E /* Resource.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 6EF44706200F9A45000B6E4E /* Resource.bundle */; };
B07118291A3264C900C8A614 /* SVIndefiniteAnimatedView.m in Sources */ = {isa = PBXBuildFile; fileRef = B07118281A3264C900C8A614 /* SVIndefiniteAnimatedView.m */; };
D36EDBD21BE7E9B000BD0EF1 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D36EDBD11BE7E9B000BD0EF1 /* main.m */; };
D36EDBD51BE7E9B000BD0EF1 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D36EDBD41BE7E9B000BD0EF1 /* AppDelegate.m */; };
Expand Down Expand Up @@ -58,6 +59,7 @@
3FF0384616633A330070E901 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
63ADC4B91364C1360060E45B /* SVProgressHUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVProgressHUD.h; sourceTree = "<group>"; };
63ADC4BA1364C1360060E45B /* SVProgressHUD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVProgressHUD.m; sourceTree = "<group>"; };
6EF44706200F9A45000B6E4E /* Resource.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Resource.bundle; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* SVProgressHUD-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "SVProgressHUD-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
B07118271A3264C900C8A614 /* SVIndefiniteAnimatedView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVIndefiniteAnimatedView.h; sourceTree = "<group>"; };
B07118281A3264C900C8A614 /* SVIndefiniteAnimatedView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVIndefiniteAnimatedView.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -96,6 +98,7 @@
children = (
63ADC4B81364C1360060E45B /* SVProgressHUD */,
28D7ACF60DDB3853001CB0EB /* ViewController.h */,
6EF44706200F9A45000B6E4E /* Resource.bundle */,
28D7ACF70DDB3853001CB0EB /* ViewController.m */,
3C0DE68E1F6096230062BA4A /* LaunchScreen.storyboard */,
3C0DE6901F6096230062BA4A /* Main.storyboard */,
Expand Down Expand Up @@ -268,6 +271,7 @@
3C0DE6921F6096230062BA4A /* LaunchScreen.storyboard in Resources */,
22D13AB71365FEAC0025FCC9 /* SVProgressHUD.bundle in Resources */,
2265DEEE14706A8900B3EBF7 /* README.md in Resources */,
6EF44707200F9A45000B6E4E /* Resource.bundle in Resources */,
3C0DE6931F6096230062BA4A /* Main.storyboard in Resources */,
22B9D43816B92E4D00E71652 /* SVProgressHUD.podspec in Resources */,
);
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ Or show a confirmation glyph before before getting dismissed a little bit later.
+ (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
+ (void)setHapticsEnabled:(BOOL)hapticsEnabled; // default is NO
+ (void)setLoadingImageView:(UIImageView)image; // default is nil, only used for SVProgressHUDAnimationTypeCustom
```

Additionally `SVProgressHUD` supports the `UIAppearance` protocol for most of the above methods.
Expand Down
6 changes: 4 additions & 2 deletions SVProgressHUD/SVProgressHUD.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ typedef NS_ENUM(NSUInteger, SVProgressHUDMaskType) {

typedef NS_ENUM(NSUInteger, SVProgressHUDAnimationType) {
SVProgressHUDAnimationTypeFlat, // default animation type, custom flat animation (indefinite animated ring)
SVProgressHUDAnimationTypeNative // iOS native UIActivityIndicatorView
SVProgressHUDAnimationTypeNative, // iOS native UIActivityIndicatorView
SVProgressHUDAnimationTypeCustom
};

typedef void (^SVProgressHUDShowCompletion)(void);
Expand Down Expand Up @@ -80,7 +81,7 @@ typedef void (^SVProgressHUDDismissCompletion)(void);
@property (assign, nonatomic) UIWindowLevel maxSupportedWindowLevel; // default is UIWindowLevelNormal

@property (assign, nonatomic) BOOL hapticsEnabled; // default is NO

@property (strong, nonatomic) UIImageView *loadingImageView; // would be used for SVProgressHUDAnimationTypeCustom
+ (void)setDefaultStyle:(SVProgressHUDStyle)style; // default is SVProgressHUDStyleLight
+ (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType; // default is SVProgressHUDMaskTypeNone
+ (void)setDefaultAnimationType:(SVProgressHUDAnimationType)type; // default is SVProgressHUDAnimationTypeFlat
Expand Down Expand Up @@ -109,6 +110,7 @@ typedef void (^SVProgressHUDDismissCompletion)(void);
+ (void)setFadeOutAnimationDuration:(NSTimeInterval)duration; // default is 0.15 seconds
+ (void)setMaxSupportedWindowLevel:(UIWindowLevel)windowLevel; // default is UIWindowLevelNormal
+ (void)setHapticsEnabled:(BOOL)hapticsEnabled; // default is NO
+ (void)setLoadingImageView:(UIImageView*) loadingImageView; // default is nil

#pragma mark - Show Methods

Expand Down
28 changes: 25 additions & 3 deletions SVProgressHUD/SVProgressHUD.m
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ + (void)setMaxSupportedWindowLevel:(UIWindowLevel)windowLevel {
+ (void)setHapticsEnabled:(BOOL)hapticsEnabled {
[self sharedView].hapticsEnabled = hapticsEnabled;
}

+ (void)setLoadingImageView:(UIImageView*) loadingImageView {
[self sharedView].loadingImageView = loadingImageView;
}
#pragma mark - Show Methods

+ (void)show {
Expand Down Expand Up @@ -437,7 +439,9 @@ - (void)updateHUDFrame {
// Check if an image or progress ring is displayed
BOOL imageUsed = (self.imageView.image) && !(self.imageView.hidden);
BOOL progressUsed = self.imageView.hidden;

BOOL isProgressRingUsed = self.progress >= 0;
CGFloat stringAndContentHeightBuffer = 80.0f;

// Calculate size of string
CGRect labelRect = CGRectZero;
CGFloat labelHeight = 0.0f;
Expand All @@ -458,6 +462,12 @@ - (void)updateHUDFrame {
// might get update if string is too large etc.
CGFloat hudWidth;
CGFloat hudHeight;

if (self.defaultAnimationType == SVProgressHUDAnimationTypeCustom && !imageUsed && !isProgressRingUsed){
hudWidth = CGRectGetWidth(self.loadingImageView.bounds) + 10;
hudHeight = CGRectGetHeight(self.loadingImageView.bounds) + 10;
stringAndContentHeightBuffer = CGRectGetHeight(self.loadingImageView.bounds) + 30;
}

CGFloat contentWidth = 0.0f;
CGFloat contentHeight = 0.0f;
Expand Down Expand Up @@ -1103,7 +1113,7 @@ - (UIView*)indefiniteAnimatedView {
indefiniteAnimatedView.strokeColor = self.foregroundColorForStyle;
indefiniteAnimatedView.strokeThickness = self.ringThickness;
indefiniteAnimatedView.radius = self.statusLabel.text ? self.ringRadius : self.ringNoTextRadius;
} else {
} else if (self.defaultAnimationType == SVProgressHUDAnimationTypeNative){
// Check if spinner exists and is an object of different class
if(_indefiniteAnimatedView && ![_indefiniteAnimatedView isKindOfClass:[UIActivityIndicatorView class]]){
[_indefiniteAnimatedView removeFromSuperview];
Expand All @@ -1117,6 +1127,14 @@ - (UIView*)indefiniteAnimatedView {
// Update styling
UIActivityIndicatorView *activityIndicatorView = (UIActivityIndicatorView*)_indefiniteAnimatedView;
activityIndicatorView.color = self.foregroundColorForStyle;
} else {
if(_indefiniteAnimatedView && ![_indefiniteAnimatedView isKindOfClass:[UIImageView class]]){
[_indefiniteAnimatedView removeFromSuperview];
_indefiniteAnimatedView = nil;
}
if(!_indefiniteAnimatedView){
_indefiniteAnimatedView = self.loadingImageView;
}
}
[_indefiniteAnimatedView sizeToFit];

Expand Down Expand Up @@ -1549,6 +1567,10 @@ - (void)setFadeOutAnimationDuration:(NSTimeInterval)duration {
if (!_isInitializing) _fadeOutAnimationDuration = duration;
}

- (void)setLoadingImageView:(UIImageView*) loadingImageView {
if (!_isInitializing) _loadingImageView = loadingImageView;
}

- (void)setMaxSupportedWindowLevel:(UIWindowLevel)maxSupportedWindowLevel {
if (!_isInitializing) _maxSupportedWindowLevel = maxSupportedWindowLevel;
}
Expand Down