From 2978a04b6832238d4d60e10f0bd95e47325e0243 Mon Sep 17 00:00:00 2001 From: Vikram <“vikram1008p@gmail.com”> Date: Wed, 27 Nov 2024 00:02:50 +0530 Subject: [PATCH] Added `indicatorColor` property to customize UIActivityIndicator color --- .../project.pbxproj | 8 +++---- .../Custom/ESRefreshTableViewController.swift | 24 +++++++++++++++---- .../ViewController.swift | 9 ++++++- .../Animator/ESRefreshFooterAnimator.swift | 8 +++++++ .../Animator/ESRefreshHeaderAnimator.swift | 8 +++++++ 5 files changed, 47 insertions(+), 10 deletions(-) diff --git a/ESPullToRefreshExample/ESPullToRefreshExample.xcodeproj/project.pbxproj b/ESPullToRefreshExample/ESPullToRefreshExample.xcodeproj/project.pbxproj index ad9f4c4..db38c17 100644 --- a/ESPullToRefreshExample/ESPullToRefreshExample.xcodeproj/project.pbxproj +++ b/ESPullToRefreshExample/ESPullToRefreshExample.xcodeproj/project.pbxproj @@ -474,7 +474,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = ESPullToRefresh/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 15.6; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.eggswift.ESPullToRefresh; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -497,7 +497,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = ESPullToRefresh/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 15.6; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.eggswift.ESPullToRefresh; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -627,7 +627,7 @@ CURRENT_PROJECT_VERSION = 2.9.2; DEVELOPMENT_TEAM = A367N9R36B; INFOPLIST_FILE = ESPullToRefreshExample/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 15.6; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MARKETING_VERSION = 2.9.2; PRODUCT_BUNDLE_IDENTIFIER = com.eggswift.ESPullToRefreshExample11; @@ -645,7 +645,7 @@ CURRENT_PROJECT_VERSION = 2.9.2; DEVELOPMENT_TEAM = A367N9R36B; INFOPLIST_FILE = ESPullToRefreshExample/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 15.6; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MARKETING_VERSION = 2.9.2; PRODUCT_BUNDLE_IDENTIFIER = com.eggswift.ESPullToRefreshExample11; diff --git a/ESPullToRefreshExample/ESPullToRefreshExample/Custom/ESRefreshTableViewController.swift b/ESPullToRefreshExample/ESPullToRefreshExample/Custom/ESRefreshTableViewController.swift index dbf5661..10dc583 100644 --- a/ESPullToRefreshExample/ESPullToRefreshExample/Custom/ESRefreshTableViewController.swift +++ b/ESPullToRefreshExample/ESPullToRefreshExample/Custom/ESRefreshTableViewController.swift @@ -56,12 +56,26 @@ public class ESRefreshTableViewController: UITableViewController { break } - self.tableView.es.addPullToRefresh(animator: header) { [weak self] in - self?.refresh() - } - self.tableView.es.addInfiniteScrolling(animator: footer) { [weak self] in - self?.loadMore() + if type == .defaultWithColor { + let header2 = ESRefreshHeaderAnimator.init(frame: CGRect.zero) + header2.indicatorColor = UIColor.red + self.tableView.es.addPullToRefresh(animator: header2) { [weak self] in + self?.refresh() + } + let footer2 = ESRefreshHeaderAnimator.init(frame: CGRect.zero) + footer2.indicatorColor = UIColor.green + self.tableView.es.addInfiniteScrolling(animator: footer2) { [weak self] in + self?.loadMore() + } + } else { + self.tableView.es.addPullToRefresh(animator: header) { [weak self] in + self?.refresh() + } + self.tableView.es.addInfiniteScrolling(animator: footer) { [weak self] in + self?.loadMore() + } } + self.tableView.refreshIdentifier = String.init(describing: type) self.tableView.expiredTimeInterval = 20.0 diff --git a/ESPullToRefreshExample/ESPullToRefreshExample/ViewController.swift b/ESPullToRefreshExample/ESPullToRefreshExample/ViewController.swift index 07915a5..2d0afcc 100644 --- a/ESPullToRefreshExample/ESPullToRefreshExample/ViewController.swift +++ b/ESPullToRefreshExample/ESPullToRefreshExample/ViewController.swift @@ -15,6 +15,7 @@ public enum ESRefreshExampleType: String { case textView = "TextView" case day = "Day" case collectionView = "CollectionView" + case defaultWithColor = "Default With Color" } public enum ESRefreshExampleListType { @@ -32,7 +33,8 @@ public class ViewController: UIViewController, UITableViewDataSource, UITableVie .wechat, .textView, .day, - .collectionView] + .collectionView, + .defaultWithColor] public override func viewDidLoad() { super.viewDidLoad() @@ -72,6 +74,11 @@ public class ViewController: UIViewController, UITableViewDataSource, UITableVie vc = ESRefreshTableViewController.init(style: .plain) case .collectionView: vc = CollectionViewController() + case .defaultWithColor: + vc = ESRefreshTableViewController.init(style: .plain) + if let vc = vc as? ESRefreshTableViewController { + vc.type = .defaultWithColor + } } vc.title = element.rawValue self.navigationController?.pushViewController(vc, animated: true) diff --git a/Sources/Animator/ESRefreshFooterAnimator.swift b/Sources/Animator/ESRefreshFooterAnimator.swift index fe05d8c..e92f019 100644 --- a/Sources/Animator/ESRefreshFooterAnimator.swift +++ b/Sources/Animator/ESRefreshFooterAnimator.swift @@ -52,6 +52,14 @@ open class ESRefreshFooterAnimator: UIView, ESRefreshProtocol, ESRefreshAnimator return indicatorView }() + open var indicatorColor: UIColor = .gray { + didSet { + if indicatorColor != oldValue { + indicatorView.color = indicatorColor + } + } + } + public override init(frame: CGRect) { super.init(frame: frame) titleLabel.text = loadingMoreDescription diff --git a/Sources/Animator/ESRefreshHeaderAnimator.swift b/Sources/Animator/ESRefreshHeaderAnimator.swift index b756918..fea7ad4 100644 --- a/Sources/Animator/ESRefreshHeaderAnimator.swift +++ b/Sources/Animator/ESRefreshHeaderAnimator.swift @@ -44,6 +44,14 @@ open class ESRefreshHeaderAnimator: UIView, ESRefreshProtocol, ESRefreshAnimator open var trigger: CGFloat = 60.0 open var executeIncremental: CGFloat = 60.0 open var state: ESRefreshViewState = .pullToRefresh + + open var indicatorColor: UIColor = .gray { + didSet { + if indicatorColor != oldValue { + indicatorView.color = indicatorColor + } + } + } fileprivate let imageView: UIImageView = { let imageView = UIImageView.init()