diff --git a/Demo/ARSLineProgress.xcodeproj/project.pbxproj b/Demo/ARSLineProgress.xcodeproj/project.pbxproj index 75a1bd6..050a635 100644 --- a/Demo/ARSLineProgress.xcodeproj/project.pbxproj +++ b/Demo/ARSLineProgress.xcodeproj/project.pbxproj @@ -22,6 +22,7 @@ 276406C21C3832B700BCE105 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 276406C11C3832B700BCE105 /* Assets.xcassets */; }; 276406C51C3832B700BCE105 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 276406C31C3832B700BCE105 /* LaunchScreen.storyboard */; }; 27E116281C55844300661F75 /* ARSLineProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27E116271C55844300661F75 /* ARSLineProgress.swift */; }; + 938FA74420460F6D00B968F1 /* ARSLineProgressCustomizationObjcExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 938FA74320460F6D00B968F1 /* ARSLineProgressCustomizationObjcExt.swift */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -55,6 +56,7 @@ 276406C41C3832B700BCE105 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 276406C61C3832B700BCE105 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 27E116271C55844300661F75 /* ARSLineProgress.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ARSLineProgress.swift; path = ../../Source/ARSLineProgress.swift; sourceTree = ""; }; + 938FA74320460F6D00B968F1 /* ARSLineProgressCustomizationObjcExt.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ARSLineProgressCustomizationObjcExt.swift; path = ../../Source/ARSLineProgressCustomizationObjcExt.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -87,8 +89,10 @@ 276406B91C3832B600BCE105 /* ARSLineProgress */ = { isa = PBXGroup; children = ( - 27E116271C55844300661F75 /* ARSLineProgress.swift */, 2734519E1DAA807000D53326 /* ARSLineProgressCustomization.swift */, + 938FA74320460F6D00B968F1 /* ARSLineProgressCustomizationObjcExt.swift */, + 27E116271C55844300661F75 /* ARSLineProgress.swift */, + 273451A41DAA81FB00D53326 /* ARSLineProgressProtocols.swift */, 2734519C1DAA807000D53326 /* ARSInfiniteLoader.swift */, 273451AC1DAA85A500D53326 /* ARSProgressLoader.swift */, 273451AE1DAA85DE00D53326 /* ARSStatus.swift */, @@ -96,7 +100,6 @@ 273451A81DAA831500D53326 /* ARSLineProgressConstants.swift */, 273451AA1DAA84AE00D53326 /* ARSLineProgressExtensions.swift */, 273451A21DAA80CD00D53326 /* ARSLineProgressTypeAliases.swift */, - 273451A41DAA81FB00D53326 /* ARSLineProgressProtocols.swift */, 276406BC1C3832B600BCE105 /* ViewController.swift */, 276406BA1C3832B600BCE105 /* AppDelegate.swift */, 276406BE1C3832B700BCE105 /* Main.storyboard */, @@ -190,6 +193,7 @@ 273451A71DAA82C800D53326 /* ARSLineProgressHelpers.swift in Sources */, 27E116281C55844300661F75 /* ARSLineProgress.swift in Sources */, 273451AD1DAA85A500D53326 /* ARSProgressLoader.swift in Sources */, + 938FA74420460F6D00B968F1 /* ARSLineProgressCustomizationObjcExt.swift in Sources */, 276406BB1C3832B600BCE105 /* AppDelegate.swift in Sources */, 273451AB1DAA84AE00D53326 /* ARSLineProgressExtensions.swift in Sources */, ); diff --git a/Demo/ARSLineProgress.xcodeproj/project.xcworkspace/xcuserdata/Johnnie.xcuserdatad/UserInterfaceState.xcuserstate b/Demo/ARSLineProgress.xcodeproj/project.xcworkspace/xcuserdata/Johnnie.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..eea8acc Binary files /dev/null and b/Demo/ARSLineProgress.xcodeproj/project.xcworkspace/xcuserdata/Johnnie.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Demo/ARSLineProgress.xcodeproj/xcuserdata/Johnnie.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Demo/ARSLineProgress.xcodeproj/xcuserdata/Johnnie.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..5663282 --- /dev/null +++ b/Demo/ARSLineProgress.xcodeproj/xcuserdata/Johnnie.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/Demo/ARSLineProgress.xcodeproj/xcuserdata/Johnnie.xcuserdatad/xcschemes/xcschememanagement.plist b/Demo/ARSLineProgress.xcodeproj/xcuserdata/Johnnie.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..cafc262 --- /dev/null +++ b/Demo/ARSLineProgress.xcodeproj/xcuserdata/Johnnie.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + ARSLineProgress.xcscheme + + orderHint + 0 + + + + diff --git a/Demo/ARSLineProgress/ViewController.swift b/Demo/ARSLineProgress/ViewController.swift index 20e7769..6913aa4 100644 --- a/Demo/ARSLineProgress/ViewController.swift +++ b/Demo/ARSLineProgress/ViewController.swift @@ -13,15 +13,18 @@ final class ViewController: UIViewController { @IBAction func showInfiniteLoader(_ sender: AnyObject) { if ARSLineProgress.shown { return } - - ARSLineProgress.showWithPresentCompetionBlock { () -> Void in + + ARSLineProgress.showWithPresentCompetionBlock("I am title") { print("Showed with completion block") } + DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(3 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: { () -> Void in - ARSLineProgress.hideWithCompletionBlock({ () -> Void in - print("Hidden with completion block") - }) + + ARSLineProgress.showSuccess() +// ARSLineProgress.hideWithCompletionBlock({ () -> Void in +// print("Hidden with completion block") +// }) }) } @@ -65,11 +68,11 @@ final class ViewController: UIViewController { } @IBAction func didTapShowSuccessButton(_ sender: AnyObject) { - ARSLineProgress.showSuccess() + ARSLineProgress.showSuccess("Success") } @IBAction func didTapShowFailButton(_ sender: AnyObject) { - ARSLineProgress.showFail() + ARSLineProgress.showFail("Fail") } @IBAction func showFullBackgroundLoader(_ sender: AnyObject) { diff --git a/Source/ARSInfiniteLoader.swift b/Source/ARSInfiniteLoader.swift index dba58e1..f787ead 100644 --- a/Source/ARSInfiniteLoader.swift +++ b/Source/ARSInfiniteLoader.swift @@ -16,6 +16,8 @@ final class ARSInfiniteLoader: ARSLoader { @objc var backgroundBlurView: UIVisualEffectView @objc var backgroundSimpleView: UIView @objc var backgroundFullView: UIView + @objc var lbTitle: UILabel = UILabel() + @objc var title: String @objc var backgroundView: UIView { switch ars_config.backgroundViewStyle { case .blur: @@ -32,9 +34,14 @@ final class ARSInfiniteLoader: ARSLoader { @objc weak var targetView: UIView? init() { + title = "" backgroundBlurView = ARSBlurredBackgroundRect().view backgroundSimpleView = ARSSimpleBackgroundRect().view backgroundFullView = ARSFullBackgroundRect().view + + lbTitle.textColor = ARS_TITLE_COLOR + lbTitle.font = UIFont.systemFont(ofSize: ARS_TITLE_SIZE) + NotificationCenter.default.addObserver(self, selector: #selector(ARSInfiniteLoader.orientationChanged(_:)), name: NSNotification.Name.UIDeviceOrientationDidChange, @@ -51,9 +58,9 @@ final class ARSInfiniteLoader: ARSLoader { ars_dispatchOnMainQueue { if let loader = ars_currentLoader { if let targetView = loader.targetView { - ars_createdFrameForBackgroundView(loader.backgroundView, onView: targetView) + ars_createdFrameForBackgroundView(loader.backgroundView, title:loader.title, onView: targetView) } else { - ars_createdFrameForBackgroundView(loader.backgroundView, onView: nil) + ars_createdFrameForBackgroundView(loader.backgroundView, title:loader.title, onView: nil) } } } @@ -63,14 +70,28 @@ final class ARSInfiniteLoader: ARSLoader { extension ARSInfiniteLoader { - func ars_showOnView(_ view: UIView?, completionBlock: (() -> Void)?) { - if ars_createdFrameForBackgroundView(backgroundView, onView: view) == false { return } - + func ars_showOnView(_ view: UIView?, title: String, completionBlock: (() -> Void)?) { + self.title = title + + if ars_createdFrameForBackgroundView(backgroundView, title:self.title, onView: view) == false { return } + + if(title.count > 0){ + lbTitle.text = self.title; + lbTitle.sizeToFit(); + let parentView = ((backgroundView as? UIVisualEffectView)?.contentView) ?? backgroundView; + parentView.addSubview(lbTitle); + + lbTitle.center = CGPoint(x:parentView.center.x, + y:parentView.frame.origin.y + backgroundView.frame.size.height - ARS_TITLE_MARGIN - lbTitle.frame.size.height); + } + + targetView = view ars_createCircles(outerCircle, middleCircle: middleCircle, innerCircle: innerCircle, + title: title, onView: ((backgroundView as? UIVisualEffectView)?.contentView) ?? backgroundView, loaderType: .infinite) ars_animateCircles(outerCircle, middleCircle: middleCircle, innerCircle: innerCircle) diff --git a/Source/ARSLineProgress.swift b/Source/ARSLineProgress.swift index 22c9f46..11e3cd0 100644 --- a/Source/ARSLineProgress.swift +++ b/Source/ARSLineProgress.swift @@ -23,34 +23,63 @@ public final class ARSLineProgress: NSObject { Will interrupt the current .Infinite loader progress and show success animation instead. */ public static func showSuccess() { - if !statusShown { ARSStatus.show(.success) } + showSuccess("") + } + + public static func showSuccess(_ title: String) { + if !statusShown { ARSStatus.show(.success, title: title) } } /** Will interrupt the current .Infinite loader progress and show fail animation instead. */ public static func showFail() { - if !statusShown { ARSStatus.show(.fail) } + showFail("") } + public static func showFail(_ title: String) { + if !statusShown { ARSStatus.show(.fail, title: title) } + } // MARK: Show Infinite Loader public static func show() { - if !shown { ARSInfiniteLoader().ars_showOnView(nil, completionBlock: nil) } + show("") + } + + public static func show(_ title: String) { + if !shown { ARSInfiniteLoader().ars_showOnView(nil, title:title, completionBlock: nil) } } + + public static func showWithPresentCompetionBlock(_ block: @escaping () -> Void) { - if !shown { ARSInfiniteLoader().ars_showOnView(nil, completionBlock: block) } + showWithPresentCompetionBlock("", block: block) + } + + public static func showWithPresentCompetionBlock(_ title: String, block: @escaping () -> Void) { + if !shown { ARSInfiniteLoader().ars_showOnView(nil, title:title, completionBlock: block) } } + + public static func ars_showOnView(_ view: UIView) { - if !shown { ARSInfiniteLoader().ars_showOnView(view, completionBlock: nil) } + ars_showOnView(view, title:"") + } + + public static func ars_showOnView(_ view: UIView, title: String) { + if !shown { ARSInfiniteLoader().ars_showOnView(view, title: title, completionBlock: nil) } } + + public static func ars_showOnView(_ view: UIView, completionBlock: @escaping () -> Void) { - if !shown { ARSInfiniteLoader().ars_showOnView(view, completionBlock: completionBlock) } + ars_showOnView(view, title:"", completionBlock:completionBlock) + } + + public static func ars_showOnView(_ view: UIView, title: String, completionBlock: @escaping () -> Void) { + if !shown { ARSInfiniteLoader().ars_showOnView(view, title: title, completionBlock: completionBlock) } } diff --git a/Source/ARSLineProgressConstants.swift b/Source/ARSLineProgressConstants.swift index 8b3dbe0..d1028cf 100644 --- a/Source/ARSLineProgressConstants.swift +++ b/Source/ARSLineProgressConstants.swift @@ -10,8 +10,8 @@ import UIKit -let ARS_BACKGROUND_VIEW_SIDE_LENGTH: CGFloat = 125.0 -let ARS_STATUS_PATH_SIDE_LENGTH: CGFloat = 125.0 +let ARS_BACKGROUND_VIEW_SIDE_LENGTH: CGFloat = 110.0 +let ARS_STATUS_PATH_SIDE_LENGTH: CGFloat = 110.0 let ARS_CIRCLE_ROTATION_TO_VALUE = 2 * CGFloat.pi let ARS_CIRCLE_ROTATION_REPEAT_COUNT = Float(UINT64_MAX) @@ -22,6 +22,11 @@ let ARS_CIRCLE_LINE_WIDTH: CGFloat = 2.0 let ARS_CIRCLE_START_ANGLE: CGFloat = -CGFloat.pi / 2 let ARS_CIRCLE_END_ANGLE: CGFloat = 0.0 +let ARS_TITLE_SIZE: CGFloat = 12.0 +let ARS_TITLE_MARGIN: CGFloat = 3.0 +let ARS_TITLE_COLOR: UIColor = UIColor.white; + + weak var ars_currentStatus: ARSLoader? var ars_currentLoader: ARSLoader? var ars_currentCompletionBlock: (() -> Void)? diff --git a/Source/ARSLineProgressCustomizationObjcExt.swift b/Source/ARSLineProgressCustomizationObjcExt.swift new file mode 100644 index 0000000..033c60f --- /dev/null +++ b/Source/ARSLineProgressCustomizationObjcExt.swift @@ -0,0 +1,144 @@ +// +// ARSLineProgressCustomizationObjcExt.swift +// ARSLineProgress +// +// Created by Johnnie on 28/02/18. +// Copyright © 2018 Iaroslav Arsenkin. All rights reserved. +// + +import UIKit + +extension ARSLineProgressConfiguration { + @objc static func ars_setShowSuccessCheckmark(show : Bool){ + showSuccessCheckmark = show; + } + + // MARK: background view + @objc static func ars_setBackgroundViewDismissTransformScale(scale : CGFloat){ + backgroundViewDismissTransformScale = scale; + } + + @objc static func ars_setBackgroundViewColor(color : CGColor){ + backgroundViewColor = color; + } + + + /// setBackgroundViewStyle + /// + /// - Parameter style: 0:blur, 1:simple, 2:full, default:blur + @objc static func ars_setBackgroundViewStyle(style : NSInteger){ + switch style { + + case 0: + backgroundViewStyle = .blur; + break; + + case 1: + backgroundViewStyle = .simple; + break; + + case 2: + backgroundViewStyle = .full; + break; + + + default: + backgroundViewStyle = .blur; + break; + } + } + + @objc static func ars_setBackgroundViewCornerRadius(radius : CGFloat){ + backgroundViewCornerRadius = radius; + } + + @objc static func ars_setBackgroundViewPresentAnimationDuration(duration : CFTimeInterval){ + backgroundViewPresentAnimationDuration = duration; + } + + @objc static func ars_setBackgroundViewDismissAnimationDuration(duration : CFTimeInterval){ + backgroundViewDismissAnimationDuration = duration; + } + + @objc static func ars_setBlurStyle(style : UIBlurEffectStyle){ + blurStyle = style; + } + + // MARK: circles + @objc static func ars_setcircleColorOuter(color : CGColor){ + circleColorOuter = color; + } + + @objc static func ars_setcircleColorMiddle(color : CGColor){ + circleColorMiddle = color; + } + + @objc static func ars_setCircleColorInner(color : CGColor){ + circleColorInner = color; + } + + @objc static func ars_setCircleRotationDurationOuter(duration : CFTimeInterval){ + circleRotationDurationOuter = duration; + } + + @objc static func ars_setCircleRotationDurationMiddle(duration : CFTimeInterval){ + circleRotationDurationMiddle = duration; + } + + @objc static func ars_setCircleRotationDurationInner(duration : CFTimeInterval){ + circleRotationDurationInner = duration; + } + + + // MARK: check mark + @objc static func ars_setCheckmarkAnimationDrawDuration(duration : CFTimeInterval){ + checkmarkAnimationDrawDuration = duration; + } + + @objc static func ars_setCheckmarkLineWidth(width : CGFloat){ + checkmarkLineWidth = width; + } + + @objc static func ars_setCheckmarkColor(color : CGColor){ + checkmarkColor = color; + } + + // MARK: success circle + @objc static func ars_setSuccessCircleAnimationDrawDuration(duration : CFTimeInterval){ + successCircleAnimationDrawDuration = duration; + } + + @objc static func ars_setSuccessCircleLineWidth(width : CGFloat){ + successCircleLineWidth = width; + } + + @objc static func ars_setSuccessCircleColor(color : CGColor){ + successCircleColor = color; + } + + // MARK: fail cross + @objc static func ars_setFailCrossAnimationDrawDuration(duration : CFTimeInterval){ + failCrossAnimationDrawDuration = duration; + } + + @objc static func ars_setFailCrossLineWidth(width : CGFloat){ + failCrossLineWidth = width; + } + + @objc static func ars_setFailCrossColor(color : CGColor){ + failCrossColor = color; + } + + // MARK: fail circel + @objc static func ars_setFailCircleAnimationDrawDuration(duration : CFTimeInterval){ + failCircleAnimationDrawDuration = duration; + } + + @objc static func ars_setFailCircleLineWidth(width : CGFloat){ + failCircleLineWidth = width; + } + + @objc static func ars_setFailCircleColor(color : CGColor){ + failCircleColor = color; + } +} diff --git a/Source/ARSLineProgressHelpers.swift b/Source/ARSLineProgressHelpers.swift index 4cbcfe7..9092708 100644 --- a/Source/ARSLineProgressHelpers.swift +++ b/Source/ARSLineProgressHelpers.swift @@ -37,9 +37,22 @@ func ars_window() -> UIWindow? { return targetWindow } -@discardableResult func ars_createdFrameForBackgroundView(_ backgroundView: UIView, onView view: UIView?) -> Bool { +func sizeForTitle(_ title : String) -> CGSize{ + if (title.count > 0){ + return title.boundingRect(with:CGSize(width:0, height:0), + options:NSStringDrawingOptions.usesLineFragmentOrigin, + attributes:[NSFontAttributeName: UIFont.systemFont(ofSize: ARS_TITLE_SIZE)], + context:nil) + .size + } + + return CGSize(width:0, height:0) +} + +@discardableResult func ars_createdFrameForBackgroundView(_ backgroundView: UIView, title: String, onView view: UIView?) -> Bool { let center: CGPoint let bounds: CGRect + let lbSize = sizeForTitle(title) if view == nil { guard let window = ars_window() else { return false } @@ -51,10 +64,15 @@ func ars_window() -> UIWindow? { center = CGPoint(x: bounds.midX, y: bounds.midY) let sideLengths = ARS_BACKGROUND_VIEW_SIDE_LENGTH - + let height = sideLengths + (lbSize.height > 0 ? lbSize.height + ARS_TITLE_MARGIN : 0) + let width = max(sideLengths, height) + switch ars_config.backgroundViewStyle { case .blur, .simple: - backgroundView.frame = CGRect(x: center.x - sideLengths / 2, y: center.y - sideLengths / 2, width: sideLengths, height: sideLengths) + backgroundView.frame = CGRect(x: center.x - width / 2, + y: center.y - height / 2, + width: width, + height: height) backgroundView.layer.cornerRadius = ars_config.backgroundViewCornerRadius case .full: backgroundView.frame = CGRect(x: bounds.minX, y: bounds.minY, width: bounds.width, height: bounds.height) @@ -104,11 +122,13 @@ class ARSFullBackgroundRect { } } -func ars_createCircles(_ outerCircle: CAShapeLayer, middleCircle: CAShapeLayer, innerCircle: CAShapeLayer, onView view: UIView, loaderType: ARSLoaderType) { +func ars_createCircles(_ outerCircle: CAShapeLayer, middleCircle: CAShapeLayer, innerCircle: CAShapeLayer, title: String, onView view: UIView, loaderType: ARSLoaderType) { let circleRadiusOuter = ARS_CIRCLE_RADIUS_OUTER let circleRadiusMiddle = ARS_CIRCLE_RADIUS_MIDDLE let circleRadiusInner = ARS_CIRCLE_RADIUS_INNER - let viewBounds = view.bounds + let lbSize = sizeForTitle(title) + let heightDiff = lbSize.height > 0 ? lbSize.height + ARS_TITLE_MARGIN : 0; + let viewBounds = CGRect(x:0, y:0, width:view.bounds.size.width, height:view.bounds.size.height - heightDiff); let arcCenter = CGPoint(x: viewBounds.midX, y: viewBounds.midY) var path: UIBezierPath diff --git a/Source/ARSLineProgressProtocols.swift b/Source/ARSLineProgressProtocols.swift index 42b931a..44c118e 100644 --- a/Source/ARSLineProgressProtocols.swift +++ b/Source/ARSLineProgressProtocols.swift @@ -13,6 +13,8 @@ import UIKit @objc protocol ARSLoader { var emptyView: UIView { get } var backgroundView: UIView { get } + @objc var title: String { get set } + @objc var lbTitle: UILabel { get set } @objc optional var outerCircle: CAShapeLayer { get set } @objc optional var middleCircle: CAShapeLayer { get set } @objc optional var innerCircle: CAShapeLayer { get set } diff --git a/Source/ARSProgressLoader.swift b/Source/ARSProgressLoader.swift index 6e61ef4..e706615 100644 --- a/Source/ARSProgressLoader.swift +++ b/Source/ARSProgressLoader.swift @@ -16,6 +16,8 @@ final class ARSProgressLoader: ARSLoader { @objc var backgroundBlurView: UIView @objc var backgroundSimpleView: UIView @objc var backgroundFullView: UIView + @objc var lbTitle: UILabel = UILabel() + @objc var title: String @objc var backgroundView: UIView { switch ars_config.backgroundViewStyle { case .blur: @@ -38,6 +40,7 @@ final class ARSProgressLoader: ARSLoader { @objc weak var targetView: UIView? init() { + title = "" backgroundBlurView = ARSBlurredBackgroundRect().view backgroundSimpleView = ARSSimpleBackgroundRect().view backgroundFullView = ARSFullBackgroundRect().view @@ -58,9 +61,9 @@ final class ARSProgressLoader: ARSLoader { ars_dispatchOnMainQueue { if let loader = ars_currentLoader { if let targetView = loader.targetView { - ars_createdFrameForBackgroundView(loader.backgroundView, onView: targetView) + ars_createdFrameForBackgroundView(loader.backgroundView, title:loader.title, onView: targetView) } else { - ars_createdFrameForBackgroundView(loader.backgroundView, onView: nil) + ars_createdFrameForBackgroundView(loader.backgroundView, title:loader.title, onView: nil) } } } @@ -73,7 +76,7 @@ extension ARSProgressLoader { // MARK: Show/Cancel func ars_showWithValue(_ value: CGFloat, onView view: UIView?, progress: Progress?, completionBlock: (() -> Void)?) { - if ars_createdFrameForBackgroundView(backgroundView, onView: view) == false { return } + if ars_createdFrameForBackgroundView(backgroundView, title:title, onView: view) == false { return } if let progress = progress { self.progress = progress } ars_currentCompletionBlock = completionBlock @@ -82,6 +85,7 @@ extension ARSProgressLoader { ars_createCircles(outerCircle, middleCircle: middleCircle, innerCircle: innerCircle, + title: title, onView: ((backgroundView as? UIVisualEffectView)?.contentView) ?? backgroundView, loaderType: .progress) ars_animateCircles(outerCircle, middleCircle: middleCircle, innerCircle: innerCircle) @@ -188,7 +192,7 @@ extension ARSProgressLoader { ars_dispatchAfter(0.9) { if ARSLineProgressConfiguration.showSuccessCheckmark { - ARSStatus.show(.success) + ARSStatus.show(.success, title: self.title) let dismissDelay = 0.5 + max(ARSLineProgressConfiguration.successCircleAnimationDrawDuration, ARSLineProgressConfiguration.checkmarkAnimationDrawDuration) @@ -202,7 +206,7 @@ extension ARSProgressLoader { } func ars_failedLoading() { - ARSStatus.show(.fail) + ARSStatus.show(.fail, title: self.title) let dismissDelay = 0.5 + max(ARSLineProgressConfiguration.failCircleAnimationDrawDuration, ARSLineProgressConfiguration.failCrossAnimationDrawDuration) ars_dispatchAfter(dismissDelay) { diff --git a/Source/ARSStatus.swift b/Source/ARSStatus.swift index 0f7a529..fb08599 100644 --- a/Source/ARSStatus.swift +++ b/Source/ARSStatus.swift @@ -21,6 +21,8 @@ final class ARSStatus: ARSLoader { @objc var backgroundBlurView: UIVisualEffectView @objc var backgroundSimpleView: UIView @objc var backgroundFullView: UIView + @objc var lbTitle: UILabel = UILabel() + @objc var title: String @objc var backgroundView: UIView { switch ars_config.backgroundViewStyle { case .blur: @@ -33,10 +35,11 @@ final class ARSStatus: ARSLoader { } init() { + title = "" backgroundBlurView = ARSBlurredBackgroundRect().view backgroundSimpleView = ARSSimpleBackgroundRect().view backgroundFullView = ARSFullBackgroundRect().view - ars_createdFrameForBackgroundView(backgroundView, onView: nil) + ars_createdFrameForBackgroundView(backgroundView, title:title, onView: nil) NotificationCenter.default.addObserver(self, selector: #selector(ARSInfiniteLoader.orientationChanged(_:)), name: NSNotification.Name.UIDeviceOrientationDidChange, @@ -53,30 +56,32 @@ final class ARSStatus: ARSLoader { ars_dispatchOnMainQueue { if let loader = ars_currentLoader { if let targetView = loader.targetView { - ars_createdFrameForBackgroundView(loader.backgroundView, onView: targetView) + ars_createdFrameForBackgroundView(loader.backgroundView, title:loader.title, onView: targetView) } else { - ars_createdFrameForBackgroundView(loader.backgroundView, onView: nil) + ars_createdFrameForBackgroundView(loader.backgroundView, title:loader.title, onView: nil) } } } } - static func show(_ type: ARSStatusType) { + static func show(_ type: ARSStatusType, title: String) { if let loader = ars_currentLoader { - ars_stopCircleAnimations(loader, completionBlock: { - drawStatus(type, loader: loader) + ars_stopCircleAnimations(loader, completionBlock: { + drawStatus(type, title:title, loader: loader) }) } else { let loader = ARSStatus() ars_presentLoader(loader, onView: nil, completionBlock: { - drawStatus(type, loader: loader) + drawStatus(type, title:title, loader: loader) }) } } - static func drawStatus(_ type: ARSStatusType, loader: ARSLoader) { + static func drawStatus(_ type: ARSStatusType, title: String, loader: ARSLoader) { ars_currentStatus = loader - + loader.title = title; + loader.lbTitle.text = title + switch type { case .success: ARSStatus.drawSuccess(loader.backgroundView)