diff --git a/ProgressHUD.podspec b/ProgressHUD.podspec index e11cfdc..db151ea 100644 --- a/ProgressHUD.podspec +++ b/ProgressHUD.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'ProgressHUD' - s.version = '13.7.3' + s.version = '13.8.0' s.license = 'MIT' s.summary = 'A lightweight and easy-to-use Progress HUD for iOS.' diff --git a/ProgressHUD/Sources/ProgressHUD.swift b/ProgressHUD/Sources/ProgressHUD.swift index f8ef36b..d65adf3 100644 --- a/ProgressHUD/Sources/ProgressHUD.swift +++ b/ProgressHUD/Sources/ProgressHUD.swift @@ -12,9 +12,7 @@ import UIKit // MARK: - AnimationType -//----------------------------------------------------------------------------------------------------------------------------------------------- public enum AnimationType: CaseIterable { - case none case systemActivityIndicator case horizontalCirclesPulse @@ -30,18 +28,14 @@ public enum AnimationType: CaseIterable { } // MARK: - AnimatedIcon -//----------------------------------------------------------------------------------------------------------------------------------------------- public enum AnimatedIcon { - case succeed case failed case added } // MARK: - AlertIcon -//----------------------------------------------------------------------------------------------------------------------------------------------- public enum AlertIcon: CaseIterable { - case heart case doc case bookmark @@ -63,36 +57,62 @@ public enum AlertIcon: CaseIterable { case search } -//----------------------------------------------------------------------------------------------------------------------------------------------- extension AlertIcon { - var image: UIImage? { switch self { - case .heart: return UIImage(systemName: "heart.fill") - case .doc: return UIImage(systemName: "doc.fill") - case .bookmark: return UIImage(systemName: "bookmark.fill") - case .moon: return UIImage(systemName: "moon.fill") - case .star: return UIImage(systemName: "star.fill") - case .exclamation: return UIImage(systemName: "exclamationmark.triangle.fill") - case .flag: return UIImage(systemName: "flag.fill") - case .message: return UIImage(systemName: "envelope.fill") - case .question: return UIImage(systemName: "questionmark.diamond.fill") - case .bolt: return UIImage(systemName: "bolt.fill") - case .shuffle: return UIImage(systemName: "shuffle") - case .eject: return UIImage(systemName: "eject.fill") - case .card: return UIImage(systemName: "creditcard.fill") - case .rotate: return UIImage(systemName: "rotate.right.fill") - case .like: return UIImage(systemName: "hand.thumbsup.fill") - case .dislike: return UIImage(systemName: "hand.thumbsdown.fill") - case .privacy: return UIImage(systemName: "hand.raised.fill") - case .cart: return UIImage(systemName: "cart.fill") - case .search: return UIImage(systemName: "magnifyingglass") + case .heart: return UIImage(systemName: "heart.fill") + case .doc: return UIImage(systemName: "doc.fill") + case .bookmark: return UIImage(systemName: "bookmark.fill") + case .moon: return UIImage(systemName: "moon.fill") + case .star: return UIImage(systemName: "star.fill") + case .exclamation: return UIImage(systemName: "exclamationmark.triangle.fill") + case .flag: return UIImage(systemName: "flag.fill") + case .message: return UIImage(systemName: "envelope.fill") + case .question: return UIImage(systemName: "questionmark.diamond.fill") + case .bolt: return UIImage(systemName: "bolt.fill") + case .shuffle: return UIImage(systemName: "shuffle") + case .eject: return UIImage(systemName: "eject.fill") + case .card: return UIImage(systemName: "creditcard.fill") + case .rotate: return UIImage(systemName: "rotate.right.fill") + case .like: return UIImage(systemName: "hand.thumbsup.fill") + case .dislike: return UIImage(systemName: "hand.thumbsdown.fill") + case .privacy: return UIImage(systemName: "hand.raised.fill") + case .cart: return UIImage(systemName: "cart.fill") + case .search: return UIImage(systemName: "magnifyingglass") } } } -// MARK: - ProgressHUD -//----------------------------------------------------------------------------------------------------------------------------------------------- +// MARK: - Banner customization +public extension ProgressHUD { + + class var colorBanner: UIColor { + get { shared.colorBanner } + set { shared.colorBanner = newValue } + } + + class var colorBannerTitle: UIColor { + get { shared.colorBannerTitle } + set { shared.colorBannerTitle = newValue } + } + + class var colorBannerMessage: UIColor { + get { shared.colorBannerMessage } + set { shared.colorBannerMessage = newValue } + } + + class var fontBannerTitle: UIFont { + get { shared.fontBannerTitle } + set { shared.fontBannerTitle = newValue } + } + + class var fontBannerMessage: UIFont { + get { shared.fontBannerMessage } + set { shared.fontBannerMessage = newValue } + } +} + +// MARK: - HUD customization public extension ProgressHUD { class var mediaSize: CGFloat { @@ -151,143 +171,144 @@ public extension ProgressHUD { } } -// MARK: - ProgressHUD -//----------------------------------------------------------------------------------------------------------------------------------------------- +// MARK: - HUD methods public extension ProgressHUD { - //------------------------------------------------------------------------------------------------------------------------------------------- class func dismiss() { - DispatchQueue.main.async { shared.dismissHUD() } } - //------------------------------------------------------------------------------------------------------------------------------------------- class func remove() { - DispatchQueue.main.async { shared.removeHUD() } } - //------------------------------------------------------------------------------------------------------------------------------------------- class func show(_ text: String? = nil, interaction: Bool = true) { - DispatchQueue.main.async { shared.setup(text: text, interaction: interaction) } } +} - // MARK: - Animated Icon - //------------------------------------------------------------------------------------------------------------------------------------------- - class func show(_ text: String? = nil, icon: AnimatedIcon, interaction: Bool = true, delay: TimeInterval? = nil) { +// MARK: - Animated Icon +public extension ProgressHUD { + class func show(_ text: String? = nil, icon: AnimatedIcon, interaction: Bool = true, delay: TimeInterval? = nil) { DispatchQueue.main.async { shared.setup(text: text, animatedIcon: icon, interaction: interaction, delay: delay) } } - //------------------------------------------------------------------------------------------------------------------------------------------- class func showSucceed(_ text: String? = nil, interaction: Bool = true, delay: TimeInterval? = nil) { - DispatchQueue.main.async { shared.setup(text: text, animatedIcon: .succeed, interaction: interaction, delay: delay) } } - //------------------------------------------------------------------------------------------------------------------------------------------- class func showFailed(_ text: String? = nil, interaction: Bool = true, delay: TimeInterval? = nil) { - DispatchQueue.main.async { shared.setup(text: text, animatedIcon: .failed, interaction: interaction, delay: delay) } } - //------------------------------------------------------------------------------------------------------------------------------------------- class func showFailed(_ error: Error?, interaction: Bool = true, delay: TimeInterval? = nil) { - DispatchQueue.main.async { shared.setup(text: error?.localizedDescription, animatedIcon: .failed, interaction: interaction, delay: delay) } } - //------------------------------------------------------------------------------------------------------------------------------------------- class func showAdded(_ text: String? = nil, interaction: Bool = true, delay: TimeInterval? = nil) { - DispatchQueue.main.async { shared.setup(text: text, animatedIcon: .added, interaction: interaction, delay: delay) } } +} - // MARK: - Static Image - //------------------------------------------------------------------------------------------------------------------------------------------- - class func show(_ text: String? = nil, icon: AlertIcon, interaction: Bool = true, delay: TimeInterval? = nil) { - - let image = icon.image?.withTintColor(shared.colorAnimation, renderingMode: .alwaysOriginal) +// MARK: - Static Image +public extension ProgressHUD { + class func show(_ text: String? = nil, icon: AlertIcon, interaction: Bool = true, delay: TimeInterval? = nil) { DispatchQueue.main.async { + let image = icon.image?.withTintColor(shared.colorAnimation, renderingMode: .alwaysOriginal) shared.setup(text: text, staticImage: image, interaction: interaction, delay: delay) } } - //------------------------------------------------------------------------------------------------------------------------------------------- class func show(_ text: String? = nil, symbol: String, interaction: Bool = true, delay: TimeInterval? = nil) { - - let image = UIImage(systemName: symbol)?.withTintColor(shared.colorAnimation, renderingMode: .alwaysOriginal) - DispatchQueue.main.async { + let image = UIImage(systemName: symbol)?.withTintColor(shared.colorAnimation, renderingMode: .alwaysOriginal) shared.setup(text: text, staticImage: image, interaction: interaction, delay: delay) } } - //------------------------------------------------------------------------------------------------------------------------------------------- class func showSuccess(_ text: String? = nil, image: UIImage? = nil, interaction: Bool = true, delay: TimeInterval? = nil) { - DispatchQueue.main.async { shared.setup(text: text, staticImage: image ?? shared.imageSuccess, interaction: interaction, delay: delay) } } - //------------------------------------------------------------------------------------------------------------------------------------------- class func showError(_ text: String? = nil, image: UIImage? = nil, interaction: Bool = true, delay: TimeInterval? = nil) { - DispatchQueue.main.async { shared.setup(text: text, staticImage: image ?? shared.imageError, interaction: interaction, delay: delay) } } - //------------------------------------------------------------------------------------------------------------------------------------------- class func showError(_ error: Error?, image: UIImage? = nil, interaction: Bool = true, delay: TimeInterval? = nil) { - DispatchQueue.main.async { shared.setup(text: error?.localizedDescription, staticImage: image ?? shared.imageError, interaction: interaction, delay: delay) } } +} - // MARK: - Progress - //------------------------------------------------------------------------------------------------------------------------------------------- - class func showProgress(_ progress: CGFloat, interaction: Bool = false) { +// MARK: - Progress +public extension ProgressHUD { + class func showProgress(_ progress: CGFloat, interaction: Bool = false) { DispatchQueue.main.async { shared.setup(text: nil, progress: progress, interaction: interaction) } } - //------------------------------------------------------------------------------------------------------------------------------------------- class func showProgress(_ text: String?, _ progress: CGFloat, interaction: Bool = false) { - DispatchQueue.main.async { shared.setup(text: text, progress: progress, interaction: interaction) } } } +// MARK: - Banner +public extension ProgressHUD { + + class func showBanner(_ title: String?, _ message: String?) { + DispatchQueue.main.async { + shared.showBanner(title: title, message: message) + } + } + + class func hideBanner() { + DispatchQueue.main.async { + shared.hideBanner() + } + } +} + // MARK: - ProgressHUD -//----------------------------------------------------------------------------------------------------------------------------------------------- public class ProgressHUD: UIView { - private var timer: Timer? + private var viewBanner: UIToolbar? + private var timerBanner: Timer? + + private var colorBanner = UIColor.clear + private var colorBannerTitle = UIColor.label + private var colorBannerMessage = UIColor.darkGray + + private var fontBannerTitle = UIFont.boldSystemFont(ofSize: 16) + private var fontBannerMessage = UIFont.systemFont(ofSize: 14) + + private var timerHUD: Timer? private var mediaSize: CGFloat = 70 private var marginSize: CGFloat = 30 @@ -320,37 +341,106 @@ public class ProgressHUD: UIView { private let keyboardDidHide = UIResponder.keyboardDidHideNotification private let orientationDidChange = UIDevice.orientationDidChangeNotification - //------------------------------------------------------------------------------------------------------------------------------------------- static let shared: ProgressHUD = { let instance = ProgressHUD() return instance } () - //------------------------------------------------------------------------------------------------------------------------------------------- convenience private init() { - self.init(frame: UIScreen.main.bounds) self.alpha = 0 } - //------------------------------------------------------------------------------------------------------------------------------------------- required internal init?(coder: NSCoder) { - super.init(coder: coder) } - //------------------------------------------------------------------------------------------------------------------------------------------- override private init(frame: CGRect) { - super.init(frame: frame) } } -// MARK: - Setup -//----------------------------------------------------------------------------------------------------------------------------------------------- +// MARK: - Banner Methods +private extension ProgressHUD { + + private func showBanner(title: String?, message: String?) { + guard let window = UIApplication.shared.windows.first else { return } + + if let banner = viewBanner { + banner.removeFromSuperview() + viewBanner = nil + } + + let title = title ?? "" + let message = message ?? "" + + let widthBanner = window.frame.width - 32 + let widthLabel = window.frame.width - 64 + + let size = CGSize(width: widthLabel, height: .greatestFiniteMagnitude) + let options: NSStringDrawingOptions = [.usesLineFragmentOrigin, .usesFontLeading] + let attributes = [NSAttributedString.Key.font: fontBannerMessage] + let attributed = NSAttributedString(string: message, attributes: attributes) + let rect = attributed.boundingRect(with: size, options: options, context: nil) + let multiline = (rect.height > fontBannerMessage.lineHeight) + + let heightBanner: CGFloat = multiline ? 80 : 64 + let heightMessage: CGFloat = multiline ? 40 : 20 + + let banner = UIToolbar(frame: CGRect(x: 16, y: -100, width: widthBanner, height: heightBanner)) + banner.backgroundColor = colorBanner + banner.layer.cornerRadius = 10 + banner.clipsToBounds = true + banner.barStyle = .default + banner.isTranslucent = true + + let labelTitle = UILabel(frame: CGRect(x: 16, y: 8, width: widthLabel, height: 24)) + labelTitle.text = title + labelTitle.font = fontBannerTitle + labelTitle.textColor = colorBannerTitle + + let labelMessage = UILabel(frame: CGRect(x: 16, y: 32, width: widthLabel, height: heightMessage)) + labelMessage.text = message + labelMessage.font = fontBannerMessage + labelMessage.textColor = colorBannerMessage + labelMessage.numberOfLines = multiline ? 2 : 1 + + banner.addSubview(labelTitle) + banner.addSubview(labelMessage) + window.addSubview(banner) + + UIView.animate(withDuration: 0.25) { + banner.frame = CGRect(x: 16, y: window.safeAreaInsets.top, width: widthBanner, height: heightBanner) + } + + timerBanner?.invalidate() + timerBanner = Timer.scheduledTimer(withTimeInterval: 3.0, repeats: false) { [weak self] _ in + guard let self = self else { return } + self.hideBanner() + } + + let tapGesture = UITapGestureRecognizer(target: self, action: #selector(hideBanner)) + banner.addGestureRecognizer(tapGesture) + + viewBanner = banner + } + + @objc private func hideBanner() { + guard let banner = viewBanner else { return } + + UIView.animate(withDuration: 0.25, animations: { + banner.frame = CGRect(x: 16, y: -100, width: banner.frame.width, height: banner.frame.height) + }) { _ in + banner.removeFromSuperview() + } + + viewBanner = nil + } +} + +// MARK: - HUD Methods private extension ProgressHUD { - //------------------------------------------------------------------------------------------------------------------------------------------- private func setup(text: String?, progress: CGFloat? = nil, animatedIcon: AnimatedIcon? = nil, staticImage: UIImage? = nil, interaction: Bool, delay: TimeInterval? = nil) { @@ -395,23 +485,18 @@ private extension ProgressHUD { } // MARK: - Delay Timer -//----------------------------------------------------------------------------------------------------------------------------------------------- private extension ProgressHUD { - //------------------------------------------------------------------------------------------------------------------------------------------- private func removeDelayTimer() { - - timer?.invalidate() - timer = nil + timerHUD?.invalidate() + timerHUD = nil } - //------------------------------------------------------------------------------------------------------------------------------------------- private func setupDelayTimer(_ text: String?, _ delay: TimeInterval?) { - let count = text?.count ?? 0 let delay = delay ?? Double(count) * 0.03 + 1.25 - timer = Timer.scheduledTimer(withTimeInterval: delay, repeats: false) { [weak self] _ in + timerHUD = Timer.scheduledTimer(withTimeInterval: delay, repeats: false) { [weak self] _ in guard let self = self else { return } self.dismissHUD() } @@ -419,21 +504,16 @@ private extension ProgressHUD { } // MARK: - Notifications -//----------------------------------------------------------------------------------------------------------------------------------------------- private extension ProgressHUD { - //------------------------------------------------------------------------------------------------------------------------------------------- private func removeNotifications() { - if (didSetupNotifications) { NotificationCenter.default.removeObserver(self) didSetupNotifications = false } } - //------------------------------------------------------------------------------------------------------------------------------------------- private func setupNotifications() { - if (!didSetupNotifications) { NotificationCenter.default.addObserver(self, selector: #selector(setupPosition(_:)), name: keyboardWillShow, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(setupPosition(_:)), name: keyboardWillHide, object: nil) @@ -446,19 +526,14 @@ private extension ProgressHUD { } // MARK: - Background View -//----------------------------------------------------------------------------------------------------------------------------------------------- private extension ProgressHUD { - //------------------------------------------------------------------------------------------------------------------------------------------- private func removeBackground() { - viewBackground?.removeFromSuperview() viewBackground = nil } - //------------------------------------------------------------------------------------------------------------------------------------------- private func setupBackground(_ interaction: Bool) { - if (viewBackground == nil) { let mainWindow = UIApplication.shared.windows.first ?? UIWindow() viewBackground = UIView(frame: bounds) @@ -470,20 +545,15 @@ private extension ProgressHUD { } } -// MARK: - HUD Toolbar -//----------------------------------------------------------------------------------------------------------------------------------------------- +// MARK: - Toolbar private extension ProgressHUD { - //------------------------------------------------------------------------------------------------------------------------------------------- private func removeToolbar() { - toolbarHUD?.removeFromSuperview() toolbarHUD = nil } - //------------------------------------------------------------------------------------------------------------------------------------------- private func setupToolbar() { - if (toolbarHUD == nil) { toolbarHUD = UIToolbar(frame: CGRect.zero) toolbarHUD?.isTranslucent = true @@ -498,19 +568,14 @@ private extension ProgressHUD { } // MARK: - Status Label -//----------------------------------------------------------------------------------------------------------------------------------------------- private extension ProgressHUD { - //------------------------------------------------------------------------------------------------------------------------------------------- private func removeStatus() { - labelStatus?.removeFromSuperview() labelStatus = nil } - //------------------------------------------------------------------------------------------------------------------------------------------- private func setupStatus(_ text: String?) { - if (labelStatus == nil) { labelStatus = UILabel() labelStatus?.textAlignment = .center @@ -527,19 +592,14 @@ private extension ProgressHUD { } // MARK: - Progress View -//----------------------------------------------------------------------------------------------------------------------------------------------- private extension ProgressHUD { - //------------------------------------------------------------------------------------------------------------------------------------------- private func removeProgressView() { - viewProgress?.removeFromSuperview() viewProgress = nil } - //------------------------------------------------------------------------------------------------------------------------------------------- private func setupProgressView(_ progress: CGFloat) { - if (viewProgress == nil) { viewProgress = ProgressView(colorProgress) viewProgress?.frame = CGRect(x: 0, y: 0, width: mediaSize, height: mediaSize) @@ -556,19 +616,14 @@ private extension ProgressHUD { } // MARK: - Animated Icon -//----------------------------------------------------------------------------------------------------------------------------------------------- private extension ProgressHUD { - //------------------------------------------------------------------------------------------------------------------------------------------- private func removeAnimatedIcon() { - viewAnimatedIcon?.removeFromSuperview() viewAnimatedIcon = nil } - //------------------------------------------------------------------------------------------------------------------------------------------- private func setupAnimatedIcon(_ animatedIcon: AnimatedIcon) { - if (viewAnimatedIcon == nil) { viewAnimatedIcon = UIView(frame: CGRect(x: 0, y: 0, width: mediaSize, height: mediaSize)) } @@ -590,19 +645,14 @@ private extension ProgressHUD { } // MARK: - Static Image -//----------------------------------------------------------------------------------------------------------------------------------------------- private extension ProgressHUD { - //------------------------------------------------------------------------------------------------------------------------------------------- private func removeStaticImage() { - viewStaticImage?.removeFromSuperview() viewStaticImage = nil } - //------------------------------------------------------------------------------------------------------------------------------------------- private func setupStaticImage(_ staticImage: UIImage) { - if (viewStaticImage == nil) { viewStaticImage = UIImageView(frame: CGRect(x: 0, y: 0, width: mediaSize, height: mediaSize)) } @@ -619,19 +669,14 @@ private extension ProgressHUD { } // MARK: - Animation View -//----------------------------------------------------------------------------------------------------------------------------------------------- private extension ProgressHUD { - //------------------------------------------------------------------------------------------------------------------------------------------- private func removeAnimationView() { - viewAnimation?.removeFromSuperview() viewAnimation = nil } - //------------------------------------------------------------------------------------------------------------------------------------------- private func setupAnimationView() { - if (viewAnimation == nil) { viewAnimation = UIView(frame: CGRect(x: 0, y: 0, width: mediaSize, height: mediaSize)) } @@ -665,12 +710,9 @@ private extension ProgressHUD { } // MARK: - Setup Sizes -//----------------------------------------------------------------------------------------------------------------------------------------------- private extension ProgressHUD { - //------------------------------------------------------------------------------------------------------------------------------------------- private func setupSizes(_ text: String?, _ animation: Bool) { - if let text { if (animation == false) || (animationType != .none) { setupSizesBoth(text) @@ -682,9 +724,7 @@ private extension ProgressHUD { } } - //------------------------------------------------------------------------------------------------------------------------------------------- private func setupSizesBoth(_ text: String) { - var rect = rectText(text) let base = mediaSize + 2 * marginSize @@ -699,9 +739,7 @@ private extension ProgressHUD { setupSizes(width, height, center, rect) } - //------------------------------------------------------------------------------------------------------------------------------------------- private func setupSizesTextOnly(_ text: String) { - var rect = rectText(text) let base = mediaSize + 2 * marginSize @@ -714,9 +752,7 @@ private extension ProgressHUD { setupSizes(width, height, CGPointZero, rect) } - //------------------------------------------------------------------------------------------------------------------------------------------- private func setupSizesTextNone() { - let width = mediaSize + 2 * marginSize let height = mediaSize + 2 * marginSize @@ -725,9 +761,7 @@ private extension ProgressHUD { setupSizes(width, height, center, CGRectZero) } - //------------------------------------------------------------------------------------------------------------------------------------------- private func setupSizes(_ width: CGFloat, _ height: CGFloat, _ center: CGPoint, _ rect: CGRect) { - toolbarHUD?.bounds = CGRect(x: 0, y: 0, width: ceil(width), height: ceil(height)) viewProgress?.center = center @@ -738,23 +772,17 @@ private extension ProgressHUD { labelStatus?.frame = rect } - //------------------------------------------------------------------------------------------------------------------------------------------- private func rectText(_ text: String) -> CGRect { - let size = CGSize(width: 250, height: 250) let attributes = [NSAttributedString.Key.font: fontStatus] - return text.boundingRect(with: size, options: .usesLineFragmentOrigin, attributes: attributes, context: nil) } } // MARK: - Setup Position -//----------------------------------------------------------------------------------------------------------------------------------------------- private extension ProgressHUD { - //------------------------------------------------------------------------------------------------------------------------------------------- @objc private func setupPosition(_ notification: Notification? = nil) { - var heightKeyboard: CGFloat = 0 var animationDuration: TimeInterval = 0 @@ -783,9 +811,7 @@ private extension ProgressHUD { }, completion: nil) } - //------------------------------------------------------------------------------------------------------------------------------------------- private func keyboardHeight() -> CGFloat { - if let keyboardWindowClass = NSClassFromString("UIRemoteKeyboardWindow"), let inputSetContainerView = NSClassFromString("UIInputSetContainerView"), let inputSetHostView = NSClassFromString("UIInputSetHostView") { @@ -809,12 +835,9 @@ private extension ProgressHUD { } // MARK: - Display, Dismiss, Remove, Destroy -//----------------------------------------------------------------------------------------------------------------------------------------------- private extension ProgressHUD { - //------------------------------------------------------------------------------------------------------------------------------------------- private func displayHUD() { - if (alpha == 0) { alpha = 1 toolbarHUD?.alpha = 0 @@ -827,9 +850,7 @@ private extension ProgressHUD { } } - //------------------------------------------------------------------------------------------------------------------------------------------- private func dismissHUD() { - if (alpha == 1) { UIView.animate(withDuration: 0.15, delay: 0, options: [.allowUserInteraction, .curveEaseIn], animations: { [self] in toolbarHUD?.transform = CGAffineTransform(scaleX: 0.3, y: 0.3) @@ -841,9 +862,7 @@ private extension ProgressHUD { } } - //------------------------------------------------------------------------------------------------------------------------------------------- private func removeHUD() { - if (alpha == 1) { toolbarHUD?.alpha = 0 destroyHUD() @@ -851,9 +870,7 @@ private extension ProgressHUD { } } - //------------------------------------------------------------------------------------------------------------------------------------------- private func destroyHUD() { - removeDelayTimer() removeNotifications() @@ -869,12 +886,9 @@ private extension ProgressHUD { } // MARK: - Animation View -//----------------------------------------------------------------------------------------------------------------------------------------------- private extension ProgressHUD { - //------------------------------------------------------------------------------------------------------------------------------------------- private func animationSystemActivityIndicator(_ view: UIView) { - let spinner = UIActivityIndicatorView(style: .large) let scale = view.frame.size.width / spinner.frame.size.width spinner.transform = CGAffineTransform(scaleX: scale, y: scale) @@ -885,9 +899,7 @@ private extension ProgressHUD { view.addSubview(spinner) } - //------------------------------------------------------------------------------------------------------------------------------------------- private func animationHorizontalCirclesPulse(_ view: UIView) { - let width = view.frame.size.width let height = view.frame.size.height @@ -923,9 +935,7 @@ private extension ProgressHUD { } } - //------------------------------------------------------------------------------------------------------------------------------------------- private func animationLineScaling(_ view: UIView) { - let width = view.frame.size.width let height = view.frame.size.height @@ -959,9 +969,7 @@ private extension ProgressHUD { } } - //------------------------------------------------------------------------------------------------------------------------------------------- private func animationSingleCirclePulse(_ view: UIView) { - let width = view.frame.size.width let height = view.frame.size.height let center = CGPoint(x: width / 2, y: height / 2) @@ -997,9 +1005,7 @@ private extension ProgressHUD { view.layer.addSublayer(layer) } - //------------------------------------------------------------------------------------------------------------------------------------------- private func animationMultipleCirclePulse(_ view: UIView) { - let width = view.frame.size.width let height = view.frame.size.height let center = CGPoint(x: width / 2, y: height / 2) @@ -1042,9 +1048,7 @@ private extension ProgressHUD { } } - //------------------------------------------------------------------------------------------------------------------------------------------- private func animationSingleCircleScaleRipple(_ view: UIView) { - let width = view.frame.size.width let height = view.frame.size.height let center = CGPoint(x: width / 2, y: height / 2) @@ -1085,9 +1089,7 @@ private extension ProgressHUD { view.layer.addSublayer(layer) } - //------------------------------------------------------------------------------------------------------------------------------------------- private func animationMultipleCircleScaleRipple(_ view: UIView) { - let width = view.frame.size.width let height = view.frame.size.height let center = CGPoint(x: width / 2, y: height / 2) @@ -1134,9 +1136,7 @@ private extension ProgressHUD { } } - //------------------------------------------------------------------------------------------------------------------------------------------- private func animationCircleSpinFade(_ view: UIView) { - let width = view.frame.size.width let spacing = 3.0 @@ -1183,9 +1183,7 @@ private extension ProgressHUD { } } - //------------------------------------------------------------------------------------------------------------------------------------------- private func animationLineSpinFade(_ view: UIView) { - let width = view.frame.size.width let height = view.frame.size.height @@ -1231,9 +1229,7 @@ private extension ProgressHUD { } } - //------------------------------------------------------------------------------------------------------------------------------------------- private func animationCircleRotateChase(_ view: UIView) { - let width = view.frame.size.width let height = view.frame.size.height let center1 = CGPoint(x: width / 2, y: height / 2) @@ -1281,9 +1277,7 @@ private extension ProgressHUD { } } - //------------------------------------------------------------------------------------------------------------------------------------------- private func animationCircleStrokeSpin(_ view: UIView) { - let width = view.frame.size.width let height = view.frame.size.height let center = CGPoint(x: width / 2, y: height / 2) @@ -1331,12 +1325,9 @@ private extension ProgressHUD { } // MARK: - Animated Icon -//----------------------------------------------------------------------------------------------------------------------------------------------- private extension ProgressHUD { - //------------------------------------------------------------------------------------------------------------------------------------------- private func animatedIconSucceed(_ view: UIView) { - let length = view.frame.width let delay = (alpha == 0) ? 0.25 : 0.0 @@ -1366,9 +1357,7 @@ private extension ProgressHUD { view.layer.addSublayer(layer) } - //------------------------------------------------------------------------------------------------------------------------------------------- private func animatedIconFailed(_ view: UIView) { - let length = view.frame.width let delay = (alpha == 0) ? 0.25 : 0.0 @@ -1407,9 +1396,7 @@ private extension ProgressHUD { } } - //------------------------------------------------------------------------------------------------------------------------------------------- private func animatedIconAdded(_ view: UIView) { - let length = view.frame.width let delay = (alpha == 0) ? 0.25 : 0.0 @@ -1450,47 +1437,37 @@ private extension ProgressHUD { } // MARK: - ProgressView -//----------------------------------------------------------------------------------------------------------------------------------------------- private class ProgressView: UIView { var color: UIColor = .systemBackground { didSet { setupLayers() } } + private var progress: CGFloat = 0 private var layerCircle = CAShapeLayer() private var layerProgress = CAShapeLayer() private var labelPercentage: UILabel = UILabel() - //------------------------------------------------------------------------------------------------------------------------------------------- convenience init(_ color: UIColor) { - self.init(frame: .zero) self.color = color } - //------------------------------------------------------------------------------------------------------------------------------------------- required init?(coder: NSCoder) { - super.init(coder: coder) } - //------------------------------------------------------------------------------------------------------------------------------------------- override init(frame: CGRect) { - super.init(frame: frame) } - //------------------------------------------------------------------------------------------------------------------------------------------- override func draw(_ rect: CGRect) { - super.draw(rect) setupLayers() } - //------------------------------------------------------------------------------------------------------------------------------------------- func setupLayers() { - subviews.forEach { $0.removeFromSuperview() } layer.sublayers?.forEach { $0.removeFromSuperlayer() } @@ -1524,9 +1501,7 @@ private class ProgressView: UIView { addSubview(labelPercentage) } - //------------------------------------------------------------------------------------------------------------------------------------------- func setProgress(_ value: CGFloat, duration: TimeInterval = 0.2) { - let animation = CABasicAnimation(keyPath: "strokeEnd") animation.duration = duration animation.fromValue = progress diff --git a/ProgressHUD/app.xcodeproj/project.pbxproj b/ProgressHUD/app.xcodeproj/project.pbxproj index fb860d9..ee7b3c5 100644 --- a/ProgressHUD/app.xcodeproj/project.pbxproj +++ b/ProgressHUD/app.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -13,6 +13,7 @@ 29D29EF91D9A59E4006CA074 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29D29EF81D9A59E4006CA074 /* AppDelegate.swift */; }; 29D29F011D9A59E4006CA074 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 29D29F001D9A59E4006CA074 /* Assets.xcassets */; }; 29D29F041D9A59E4006CA074 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 29D29F021D9A59E4006CA074 /* LaunchScreen.storyboard */; }; + 29D99E7E2AC4A3300073EE38 /* NavController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29D99E7D2AC4A3300073EE38 /* NavController.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -24,6 +25,7 @@ 29D29F001D9A59E4006CA074 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 29D29F031D9A59E4006CA074 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29D29F051D9A59E4006CA074 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 29D99E7D2AC4A3300073EE38 /* NavController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavController.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -69,6 +71,7 @@ 29D29F001D9A59E4006CA074 /* Assets.xcassets */, 29D29F051D9A59E4006CA074 /* Info.plist */, 29D29F021D9A59E4006CA074 /* LaunchScreen.storyboard */, + 29D99E7D2AC4A3300073EE38 /* NavController.swift */, 295B8481248C1C5B003E8AE6 /* ViewController.swift */, 295B8480248C1C5B003E8AE6 /* ViewController.xib */, ); @@ -101,7 +104,8 @@ 29D29EE91D9A59E4006CA074 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1240; + BuildIndependentTargetsInParallel = YES; + LastUpgradeCheck = 1500; ORGANIZATIONNAME = KZ; TargetAttributes = { 29D29EF01D9A59E4006CA074 = { @@ -161,6 +165,7 @@ 295B8483248C1C5B003E8AE6 /* ViewController.swift in Sources */, 29D29EF91D9A59E4006CA074 /* AppDelegate.swift in Sources */, 299876DB248FCB290025E297 /* ProgressHUD.swift in Sources */, + 29D99E7E2AC4A3300073EE38 /* NavController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -214,6 +219,7 @@ DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -228,7 +234,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -272,6 +278,7 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -280,7 +287,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_COMPILATION_MODE = wholemodule; @@ -306,7 +313,7 @@ INFOPLIST_FILE = app/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited)"; - MARKETING_VERSION = 13.6.2; + MARKETING_VERSION = 13.8.0; PRODUCT_BUNDLE_IDENTIFIER = com.relatedcode.progresshud; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -336,7 +343,7 @@ INFOPLIST_FILE = app/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited)"; - MARKETING_VERSION = 13.6.2; + MARKETING_VERSION = 13.8.0; PRODUCT_BUNDLE_IDENTIFIER = com.relatedcode.progresshud; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/ProgressHUD/app/AppDelegate.swift b/ProgressHUD/app/AppDelegate.swift index 8ddf794..5d16019 100644 --- a/ProgressHUD/app/AppDelegate.swift +++ b/ProgressHUD/app/AppDelegate.swift @@ -11,19 +11,16 @@ import UIKit -//----------------------------------------------------------------------------------------------------------------------------------------------- @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - //------------------------------------------------------------------------------------------------------------------------------------------- func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { - window = UIWindow(frame: UIScreen.main.bounds) let viewController = ViewController(nibName: "ViewController", bundle: nil) - let navController = UINavigationController(rootViewController: viewController) + let navController = NavigationController(rootViewController: viewController) window?.rootViewController = navController window?.makeKeyAndVisible() diff --git a/ProgressHUD/app/NavController.swift b/ProgressHUD/app/NavController.swift new file mode 100644 index 0000000..304cfa0 --- /dev/null +++ b/ProgressHUD/app/NavController.swift @@ -0,0 +1,41 @@ +// +// Copyright (c) 2023 Related Code - https://relatedcode.com +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import UIKit + +class NavigationController: UINavigationController { + + override func viewDidLoad() { + super.viewDidLoad() + + isModalInPresentation = true + modalPresentationStyle = .fullScreen + + navigationBar.isTranslucent = true + + navigationBar.tintColor = .white + navigationBar.barTintColor = .systemGreen + navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] + + if #available(iOS 15, *) { + let appearance = UINavigationBarAppearance() + appearance.configureWithOpaqueBackground() + appearance.backgroundColor = .systemGreen + appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] + UINavigationBar.appearance().standardAppearance = appearance + UINavigationBar.appearance().scrollEdgeAppearance = appearance + } + } + + override var preferredStatusBarStyle: UIStatusBarStyle { + return .lightContent + } +} diff --git a/ProgressHUD/app/ViewController.swift b/ProgressHUD/app/ViewController.swift index ecb7420..9f9e9ce 100644 --- a/ProgressHUD/app/ViewController.swift +++ b/ProgressHUD/app/ViewController.swift @@ -11,87 +11,54 @@ import UIKit -//----------------------------------------------------------------------------------------------------------------------------------------------- +// MARK: - AnimationType extension AnimationType { - - var name: String { + var text: String { switch self { - case .none: - return "No Animation" - case .systemActivityIndicator: - return "System Activity Indicator" - case .horizontalCirclesPulse: - return "Horizontal Circles Pulse" - case .lineScaling: - return "Line Scaling" - case .singleCirclePulse: - return "Single Circle Pulse" - case .multipleCirclePulse: - return "Multiple Circle Pulse" - case .singleCircleScaleRipple: - return "Single Circle Scale Ripple" - case .multipleCircleScaleRipple: - return "Multiple Circle Scale Ripple" - case .circleSpinFade: - return "Circle Spin Fade" - case .lineSpinFade: - return "Line Spin Fade" - case .circleRotateChase: - return "Circle Rotate Chase" - case .circleStrokeSpin: - return "Circle Stroke Spin" + case .none: return "No Animation" + case .systemActivityIndicator: return "System Activity Indicator" + case .horizontalCirclesPulse: return "Horizontal Circles Pulse" + case .lineScaling: return "Line Scaling" + case .singleCirclePulse: return "Single Circle Pulse" + case .multipleCirclePulse: return "Multiple Circle Pulse" + case .singleCircleScaleRipple: return "Single Circle Scale Ripple" + case .multipleCircleScaleRipple: return "Multiple Circle Scale Ripple" + case .circleSpinFade: return "Circle Spin Fade" + case .lineSpinFade: return "Line Spin Fade" + case .circleRotateChase: return "Circle Rotate Chase" + case .circleStrokeSpin: return "Circle Stroke Spin" } } } -//----------------------------------------------------------------------------------------------------------------------------------------------- +// MARK: - AlertIcon extension AlertIcon { - - var name: String { + var text: String { switch self { - case .heart: - return "Heart" - case .doc: - return "Doc" - case .bookmark: - return "Bookmark" - case .moon: - return "Moon" - case .star: - return "Star" - case .exclamation: - return "Exclamation" - case .flag: - return "Flag" - case .message: - return "Message" - case .question: - return "Question" - case .bolt: - return "Bolt" - case .shuffle: - return "Shuffle" - case .eject: - return "Eject" - case .card: - return "Card" - case .rotate: - return "Rotate" - case .like: - return "Like" - case .dislike: - return "Dislike" - case .privacy: - return "Privacy" - case .cart: - return "Cart" - case .search: - return "Search" + case .heart: return "Heart" + case .doc: return "Doc" + case .bookmark: return "Bookmark" + case .moon: return "Moon" + case .star: return "Star" + case .exclamation: return "Exclamation" + case .flag: return "Flag" + case .message: return "Message" + case .question: return "Question" + case .bolt: return "Bolt" + case .shuffle: return "Shuffle" + case .eject: return "Eject" + case .card: return "Card" + case .rotate: return "Rotate" + case .like: return "Like" + case .dislike: return "Dislike" + case .privacy: return "Privacy" + case .cart: return "Cart" + case .search: return "Search" } } } -//----------------------------------------------------------------------------------------------------------------------------------------------- +// MARK: - ViewController class ViewController: UITableViewController { @IBOutlet var cellText: UITableViewCell! @@ -119,9 +86,9 @@ class ViewController: UITableViewController { private let textFailed = "Something went wrong." private let textAdded = "Successfully added." - //------------------------------------------------------------------------------------------------------------------------------------------- - override func viewDidLoad() { + private var boolText = false + override func viewDidLoad() { super.viewDidLoad() title = "ProgressHUD" @@ -155,13 +122,10 @@ class ViewController: UITableViewController { } } -// MARK: - Progress methods -//----------------------------------------------------------------------------------------------------------------------------------------------- +// MARK: - Progress Methods extension ViewController { - //------------------------------------------------------------------------------------------------------------------------------------------- func actionProgressStart(_ status: String? = nil) { - counter = 0 ProgressHUD.showProgress(status, counter/100) @@ -171,9 +135,7 @@ extension ViewController { } } - //------------------------------------------------------------------------------------------------------------------------------------------- func actionProgress(_ status: String?) { - counter += 1 ProgressHUD.showProgress(status, counter/100) @@ -182,9 +144,7 @@ extension ViewController { } } - //------------------------------------------------------------------------------------------------------------------------------------------- func actionProgressStop(_ status: String?) { - timer?.invalidate() timer = nil @@ -195,140 +155,146 @@ extension ViewController { } // MARK: - UITableViewDataSource -//----------------------------------------------------------------------------------------------------------------------------------------------- extension ViewController { - //------------------------------------------------------------------------------------------------------------------------------------------- override func numberOfSections(in tableView: UITableView) -> Int { - - return 8 + return 9 } - //------------------------------------------------------------------------------------------------------------------------------------------- override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + if (section == 0) { return 2 } + if (section == 1) { return 4 } - if (section == 0) { return 4 } - if (section == 1) { return animations.count } - if (section == 2) { return actions1.count } - if (section == 3) { return actions2.count } - if (section == 4) { return actions3.count } - if (section == 5) { return actions4.count } - if (section == 6) { return actions5.count } - if (section == 7) { return alerticons.count } + if (section == 2) { return animations.count } + if (section == 3) { return actions1.count } + if (section == 4) { return actions2.count } + if (section == 5) { return actions3.count } + if (section == 6) { return actions4.count } + if (section == 7) { return actions5.count } + if (section == 8) { return alerticons.count } return 0 } - //------------------------------------------------------------------------------------------------------------------------------------------- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - - if (indexPath.section == 0) && (indexPath.row == 0) { return cellText } - - if (indexPath.section == 0) && (indexPath.row == 1) { return self.tableView(tableView, cellWithText: "Dismiss Keyboard") } - if (indexPath.section == 0) && (indexPath.row == 2) { return self.tableView(tableView, cellWithText: "Dismiss HUD") } - if (indexPath.section == 0) && (indexPath.row == 3) { return self.tableView(tableView, cellWithText: "Remove HUD") } - - if (indexPath.section == 1) { return self.tableView(tableView, cellWithText: animations[indexPath.row].name) } - if (indexPath.section == 2) { return self.tableView(tableView, cellWithText: actions1[indexPath.row]) } - if (indexPath.section == 3) { return self.tableView(tableView, cellWithText: actions2[indexPath.row]) } - if (indexPath.section == 4) { return self.tableView(tableView, cellWithText: actions3[indexPath.row]) } - if (indexPath.section == 5) { return self.tableView(tableView, cellWithText: actions4[indexPath.row]) } - if (indexPath.section == 6) { return self.tableView(tableView, cellWithText: actions5[indexPath.row]) } - if (indexPath.section == 7) { return self.tableView(tableView, cellWithText: alerticons[indexPath.row].name) } + if (indexPath.section == 0) && (indexPath.row == 0) { return self.tableView(tableView, cellWithText: "Show Banner") } + if (indexPath.section == 0) && (indexPath.row == 1) { return self.tableView(tableView, cellWithText: "Hide Banner") } + + if (indexPath.section == 1) && (indexPath.row == 0) { return cellText } + if (indexPath.section == 1) && (indexPath.row == 1) { return self.tableView(tableView, cellWithText: "Dismiss Keyboard") } + if (indexPath.section == 1) && (indexPath.row == 2) { return self.tableView(tableView, cellWithText: "Dismiss HUD") } + if (indexPath.section == 1) && (indexPath.row == 3) { return self.tableView(tableView, cellWithText: "Remove HUD") } + + if (indexPath.section == 2) { return self.tableView(tableView, cellWithText: animations[indexPath.row].text) } + if (indexPath.section == 3) { return self.tableView(tableView, cellWithText: actions1[indexPath.row]) } + if (indexPath.section == 4) { return self.tableView(tableView, cellWithText: actions2[indexPath.row]) } + if (indexPath.section == 5) { return self.tableView(tableView, cellWithText: actions3[indexPath.row]) } + if (indexPath.section == 6) { return self.tableView(tableView, cellWithText: actions4[indexPath.row]) } + if (indexPath.section == 7) { return self.tableView(tableView, cellWithText: actions5[indexPath.row]) } + if (indexPath.section == 8) { return self.tableView(tableView, cellWithText: alerticons[indexPath.row].text) } return UITableViewCell() } - //------------------------------------------------------------------------------------------------------------------------------------------- func tableView(_ tableView: UITableView, cellWithText text: String) -> UITableViewCell { - var cell: UITableViewCell! = tableView.dequeueReusableCell(withIdentifier: "cell") if (cell == nil) { cell = UITableViewCell(style: .default, reuseIdentifier: "cell") } cell.textLabel?.text = text - return cell } - //------------------------------------------------------------------------------------------------------------------------------------------- override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { - - if (section == 1) { return "Animation Types" } - if (section == 2) { return "Animation" } - if (section == 3) { return "Progress" } + if (section == 0) { return "Banner Actions" } + if (section == 1) { return "HUD Actions" } + if (section == 2) { return "Animation Types" } + if (section == 3) { return "Animation" } if (section == 4) { return "Progress" } - if (section == 5) { return "Action - Static" } - if (section == 6) { return "Action - Animated" } - if (section == 7) { return "Alert Icons" } - + if (section == 5) { return "Progress" } + if (section == 6) { return "Action - Static" } + if (section == 7) { return "Action - Animated" } + if (section == 8) { return "Alert Icons" } return nil } } // MARK: - UITableViewDelegate -//----------------------------------------------------------------------------------------------------------------------------------------------- extension ViewController { - //------------------------------------------------------------------------------------------------------------------------------------------- override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - tableView.deselectRow(at: indexPath, animated: true) - if (indexPath.section == 0) && (indexPath.row == 1) { view.endEditing(true) } - if (indexPath.section == 0) && (indexPath.row == 2) { ProgressHUD.dismiss() } - if (indexPath.section == 0) && (indexPath.row == 3) { ProgressHUD.remove() } + if (indexPath.section == 0) { + let title = "Banner title" + let message = toggleText() - if (indexPath.section == 1) { - ProgressHUD.animationType = animations[indexPath.row] - ProgressHUD.show(status) + if (indexPath.row == 0) { ProgressHUD.showBanner(title, message) } + if (indexPath.row == 1) { ProgressHUD.hideBanner() } + } + + if (indexPath.section == 1) { + if (indexPath.row == 1) { view.endEditing(true) } + if (indexPath.row == 2) { ProgressHUD.dismiss() } + if (indexPath.row == 3) { ProgressHUD.remove() } } - if (indexPath.section == 2) { - if (indexPath.row == 0) { ProgressHUD.show(); status = nil } - if (indexPath.row == 1) { ProgressHUD.show(textShort); status = textShort } - if (indexPath.row == 2) { ProgressHUD.show(textLong); status = textLong } + if (indexPath.section == 2) { + ProgressHUD.animationType = animations[indexPath.row] + ProgressHUD.show(status) } if (indexPath.section == 3) { - if (indexPath.row == 0) { actionProgressStart() } - if (indexPath.row == 1) { actionProgressStart(textShort) } - if (indexPath.row == 2) { actionProgressStart(textLong) } + if (indexPath.row == 0) { ProgressHUD.show(); status = nil } + if (indexPath.row == 1) { ProgressHUD.show(textShort); status = textShort } + if (indexPath.row == 2) { ProgressHUD.show(textLong); status = textLong } } if (indexPath.section == 4) { - if (indexPath.row == 0) { ProgressHUD.showProgress(0.1, interaction: true) } - if (indexPath.row == 1) { ProgressHUD.showProgress(0.4, interaction: true) } - if (indexPath.row == 2) { ProgressHUD.showProgress(0.6, interaction: true) } - if (indexPath.row == 3) { ProgressHUD.showProgress(0.9, interaction: true) } + if (indexPath.row == 0) { actionProgressStart() } + if (indexPath.row == 1) { actionProgressStart(textShort) } + if (indexPath.row == 2) { actionProgressStart(textLong) } } if (indexPath.section == 5) { - if (indexPath.row == 0) { ProgressHUD.showSuccess() } - if (indexPath.row == 1) { ProgressHUD.showSuccess(textSuccess) } - if (indexPath.row == 2) { ProgressHUD.showError() } - if (indexPath.row == 3) { ProgressHUD.showError(textError) } + if (indexPath.row == 0) { ProgressHUD.showProgress(0.1, interaction: true) } + if (indexPath.row == 1) { ProgressHUD.showProgress(0.4, interaction: true) } + if (indexPath.row == 2) { ProgressHUD.showProgress(0.6, interaction: true) } + if (indexPath.row == 3) { ProgressHUD.showProgress(0.9, interaction: true) } } if (indexPath.section == 6) { - if (indexPath.row == 0) { ProgressHUD.showSucceed() } - if (indexPath.row == 1) { ProgressHUD.showSucceed(textSucceed) } - if (indexPath.row == 2) { ProgressHUD.showFailed() } - if (indexPath.row == 3) { ProgressHUD.showFailed(textFailed) } - if (indexPath.row == 4) { ProgressHUD.showAdded() } - if (indexPath.row == 5) { ProgressHUD.showAdded(textAdded) } + if (indexPath.row == 0) { ProgressHUD.showSuccess() } + if (indexPath.row == 1) { ProgressHUD.showSuccess(textSuccess) } + if (indexPath.row == 2) { ProgressHUD.showError() } + if (indexPath.row == 3) { ProgressHUD.showError(textError) } } if (indexPath.section == 7) { + if (indexPath.row == 0) { ProgressHUD.showSucceed() } + if (indexPath.row == 1) { ProgressHUD.showSucceed(textSucceed) } + if (indexPath.row == 2) { ProgressHUD.showFailed() } + if (indexPath.row == 3) { ProgressHUD.showFailed(textFailed) } + if (indexPath.row == 4) { ProgressHUD.showAdded() } + if (indexPath.row == 5) { ProgressHUD.showAdded(textAdded) } + } + + if (indexPath.section == 8) { let alerticon = alerticons[indexPath.row] ProgressHUD.show(randomText(), icon: alerticon) } } +} - //------------------------------------------------------------------------------------------------------------------------------------------- - func randomText() -> String? { +// MARK: - Text Methods +extension ViewController { + func randomText() -> String? { let array = [textShort, textLong, textSucceed, textFailed, textAdded, nil] let index = Int.random(in: 0.. String { + boolText = !boolText + return boolText ? textAdded : textLong + } } diff --git a/ProgressHUD/app/ViewController.xib b/ProgressHUD/app/ViewController.xib index df4ad1e..9ec0186 100644 --- a/ProgressHUD/app/ViewController.xib +++ b/ProgressHUD/app/ViewController.xib @@ -1,9 +1,9 @@ - + - + diff --git a/README.md b/README.md index f270d43..910e836 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ ## WHAT'S NEW +### Version: 13.8.0 + +- Introduced an incredibly straightforward notification banner feature. + ### Version: 13.7.3 - Fixed a bug where a thin line occasionally appeared on the right side of the HUD. @@ -50,11 +54,12 @@ pod 'ProgressHUD' [Swift Package Manager](https://swift.org/package-manager) is a tool for managing the distribution of Swift code. -Once you've configured your `Package.swift` manifest file, you may proceed to include **ProgressHUD** in the dependencies section of the same file. +To add **ProgressHUD** as a dependency to your project, follow these steps: -```swift -dependencies: [ .package(url: "https://github.com/relatedcode/ProgressHUD.git", from: "13.7.3") ] -``` +1. Open your Swift project in Xcode. +2. Navigate to `File` -> `Add Package Dependencies...`. +3. Paste `https://github.com/relatedcode/ProgressHUD.git` into the search bar. +4. Choose the version you want to use and click `Add Package`. ### Manually @@ -62,6 +67,14 @@ If you prefer not to use any of the dependency managers, you can integrate **Pro ## QUICK START +```swift +ProgressHUD.showBanner("Banner title", "Banner message to display.") +``` + +```swift +ProgressHUD.hideBanner() +``` + ```swift ProgressHUD.show("Some text...") ```