From ddb64240460cfee88d0453ee3f172191267437ee Mon Sep 17 00:00:00 2001 From: Shwet Solanki Date: Sun, 18 Mar 2018 17:49:08 +0530 Subject: [PATCH 1/5] feat(emptystate): Adds containerview for UIEmptyState --- UIEmptyState/UIEmptyStateDataSource.swift | 4 ++++ UIEmptyState/UIViewController+UIEmptyState.swift | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/UIEmptyState/UIEmptyStateDataSource.swift b/UIEmptyState/UIEmptyStateDataSource.swift index 670e3de..aaf8f2d 100644 --- a/UIEmptyState/UIEmptyStateDataSource.swift +++ b/UIEmptyState/UIEmptyStateDataSource.swift @@ -159,6 +159,8 @@ public protocol UIEmptyStateDataSource: class { */ func emptyStateViewAnimation(for view: UIView, animationDuration: TimeInterval, completion: ((Bool) -> Void)?) -> Void + + var emptyStateContainerView: UIView { get } } /// Extension for the UIEmptyDataSource which adds a default implementation for any UIViewController Subclass @@ -260,6 +262,8 @@ extension UIEmptyStateDataSource where Self: UIViewController { /// Default implementation of `emptyStateViewAnimationDuration`, returns `0.5` public var emptyStateViewAnimationDuration: TimeInterval { get { return 0.5 } } + public var emptyStateContainerView: UIView { return self.view } + /// Default implementation of `emptyStateViewAnimation`, implements a simple animation public func emptyStateViewAnimation(for view: UIView, animationDuration: TimeInterval, completion: ((Bool) -> Void)?) -> Void { diff --git a/UIEmptyState/UIViewController+UIEmptyState.swift b/UIEmptyState/UIViewController+UIEmptyState.swift index 70347e1..a2eb1b7 100644 --- a/UIEmptyState/UIViewController+UIEmptyState.swift +++ b/UIEmptyState/UIViewController+UIEmptyState.swift @@ -137,9 +137,9 @@ extension UIViewController { //// Private helper which creates view contraints for the UIEmptyStateView. private func createViewConstraints(for view: UIView, in source: UIEmptyStateDataSource) { // Set constraints - var centerX = view.centerXAnchor.constraint(equalTo: self.view.centerXAnchor) + var centerX = view.centerXAnchor.constraint(equalTo: source.emptyStateContainerView.centerXAnchor) centerX.isActive = true - var centerY = view.centerYAnchor.constraint(equalTo: self.view.centerYAnchor) + var centerY = view.centerYAnchor.constraint(equalTo: source.emptyStateContainerView.centerYAnchor) centerY.isActive = true // If iOS 11.0 is not available, then adjust the extended layout accordingly using older API @@ -160,11 +160,11 @@ extension UIViewController { if source.emptyStateViewAdjustsToFitBars { // Adjust constraint to fit new big title bars, etc centerX.isActive = false - centerX = view.centerXAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.centerXAnchor) + centerX = view.centerXAnchor.constraint(equalTo: source.emptyStateContainerView.safeAreaLayoutGuide.centerXAnchor) centerX.isActive = true centerY.isActive = false - centerY = view.centerYAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.centerYAnchor) + centerY = view.centerYAnchor.constraint(equalTo: source.emptyStateContainerView.safeAreaLayoutGuide.centerYAnchor) centerY.isActive = true } @@ -216,8 +216,10 @@ extension UIViewController { // Add to emptyStateView property emptyView = newView // Add as a subView, bring it infront of the tableView - self.view.addSubview(newView) - self.view.bringSubview(toFront: newView) + + self.emptyStateDataSource?.emptyStateContainerView.addSubview(newView) + self.emptyStateDataSource?.emptyStateContainerView.sendSubview(toBack: newView) + // Animate now if source.emptyStateViewCanAnimate { DispatchQueue.main.async { From b436a096da354fb903ee62f8971e3c68de3f8cf7 Mon Sep 17 00:00:00 2001 From: Shwet Solanki Date: Thu, 5 Apr 2018 14:54:16 +0530 Subject: [PATCH 2/5] fix(delegates): Changed .OBJC_ASSOCIATION_RETAIN to OBJC_ASSOCIATION_ASSIGN to avoid retain cycles --- UIEmptyState/UIViewController+UIEmptyState.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UIEmptyState/UIViewController+UIEmptyState.swift b/UIEmptyState/UIViewController+UIEmptyState.swift index a2eb1b7..65b2801 100644 --- a/UIEmptyState/UIViewController+UIEmptyState.swift +++ b/UIEmptyState/UIViewController+UIEmptyState.swift @@ -25,7 +25,7 @@ extension UIViewController { */ public weak var emptyStateDataSource: UIEmptyStateDataSource? { get { return objc_getAssociatedObject(self, &Keys.emptyStateDataSource) as? UIEmptyStateDataSource } - set { objc_setAssociatedObject(self, &Keys.emptyStateDataSource, newValue, .OBJC_ASSOCIATION_RETAIN) } + set { objc_setAssociatedObject(self, &Keys.emptyStateDataSource, newValue, .OBJC_ASSOCIATION_ASSIGN) } } /** @@ -36,7 +36,7 @@ extension UIViewController { */ public weak var emptyStateDelegate: UIEmptyStateDelegate? { get { return objc_getAssociatedObject(self, &Keys.emptyStateDelegate) as? UIEmptyStateDelegate } - set { objc_setAssociatedObject(self, &Keys.emptyStateDelegate, newValue, .OBJC_ASSOCIATION_RETAIN) } + set { objc_setAssociatedObject(self, &Keys.emptyStateDelegate, newValue, .OBJC_ASSOCIATION_ASSIGN) } } /** From 9f2eb3e16b38acbef84c43e7e6d78a2ec5563b81 Mon Sep 17 00:00:00 2001 From: Shwet Solanki Date: Thu, 5 Apr 2018 14:55:23 +0530 Subject: [PATCH 3/5] build(podspec): updated version --- UIEmptyState.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UIEmptyState.podspec b/UIEmptyState.podspec index 0a1f6a8..502c8d8 100644 --- a/UIEmptyState.podspec +++ b/UIEmptyState.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = "UIEmptyState" - s.version = "3.1.0" + s.version = "3.1.1" s.summary = "An empty state control to give visually appealing context when building iOS applications." s.description = <<-DESC Empty state control which gives context with either a message, image, and buttons to the user when ever there is a reason the state is empty. From f88731fcfcaa71e3736655fa51a320a0981acb2a Mon Sep 17 00:00:00 2001 From: Vinita Miranda Date: Tue, 26 May 2020 23:18:58 +0530 Subject: [PATCH 4/5] feat(swift5.2): Migrating to swift 5.2 --- Example/Podfile.lock | 8 +++--- .../project.pbxproj | 27 +++++-------------- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++ Example/UIEmptyStateExample/AppDelegate.swift | 2 +- .../EmptyStateTableViewController.swift | 10 +++---- UIEmptyState/UIEmptyStateView.swift | 2 +- .../UIViewController+UIEmptyState.swift | 2 +- 7 files changed, 26 insertions(+), 33 deletions(-) create mode 100644 Example/UIEmptyStateExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 3c05903..7e79c5a 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,16 +1,16 @@ PODS: - - UIEmptyState (3.1.0) + - UIEmptyState (3.1.1) DEPENDENCIES: - UIEmptyState (from `../`) EXTERNAL SOURCES: UIEmptyState: - :path: ../ + :path: "../" SPEC CHECKSUMS: - UIEmptyState: 9b501dc90933ce2743949ecbf18c20ffb33a2be9 + UIEmptyState: 801fb97bc13d0ec75e32ba0a111538683aea69f5 PODFILE CHECKSUM: 2410e5e41e5d4570ddd34538c5ba93d5d35ce08c -COCOAPODS: 1.3.1 +COCOAPODS: 1.9.1 diff --git a/Example/UIEmptyStateExample.xcodeproj/project.pbxproj b/Example/UIEmptyStateExample.xcodeproj/project.pbxproj index 0fd53f7..89c8f8a 100644 --- a/Example/UIEmptyStateExample.xcodeproj/project.pbxproj +++ b/Example/UIEmptyStateExample.xcodeproj/project.pbxproj @@ -122,7 +122,6 @@ A05AA1BB1E4560E800B851F7 /* Frameworks */, A05AA1BC1E4560E800B851F7 /* Resources */, 0085D2E6DEBEFB5796183033 /* [CP] Embed Pods Frameworks */, - 24B3590701ADC38465D2548E /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -146,7 +145,7 @@ A05AA1BD1E4560E800B851F7 = { CreatedOnToolsVersion = 8.2.1; DevelopmentTeam = 4FNMZ7SN42; - LastSwiftMigration = 0900; + LastSwiftMigration = 1140; ProvisioningStyle = Automatic; }; }; @@ -156,6 +155,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -189,7 +189,7 @@ files = ( ); inputPaths = ( - "${SRCROOT}/Pods/Target Support Files/Pods-UIEmptyStateExample/Pods-UIEmptyStateExample-frameworks.sh", + "${PODS_ROOT}/Target Support Files/Pods-UIEmptyStateExample/Pods-UIEmptyStateExample-frameworks.sh", "${BUILT_PRODUCTS_DIR}/UIEmptyState/UIEmptyState.framework", ); name = "[CP] Embed Pods Frameworks"; @@ -198,22 +198,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-UIEmptyStateExample/Pods-UIEmptyStateExample-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; - 24B3590701ADC38465D2548E /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-UIEmptyStateExample/Pods-UIEmptyStateExample-resources.sh\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-UIEmptyStateExample/Pods-UIEmptyStateExample-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; 7D72286EB8A21429E4DC3E74 /* [CP] Check Pods Manifest.lock */ = { @@ -386,7 +371,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.luispadron.UIEmptyStateExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -401,7 +386,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.luispadron.UIEmptyStateExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Off; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/Example/UIEmptyStateExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Example/UIEmptyStateExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Example/UIEmptyStateExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Example/UIEmptyStateExample/AppDelegate.swift b/Example/UIEmptyStateExample/AppDelegate.swift index e10d861..de7b36d 100644 --- a/Example/UIEmptyStateExample/AppDelegate.swift +++ b/Example/UIEmptyStateExample/AppDelegate.swift @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } diff --git a/Example/UIEmptyStateExample/EmptyStateTableViewController.swift b/Example/UIEmptyStateExample/EmptyStateTableViewController.swift index b5de404..0998a5c 100644 --- a/Example/UIEmptyStateExample/EmptyStateTableViewController.swift +++ b/Example/UIEmptyStateExample/EmptyStateTableViewController.swift @@ -33,14 +33,14 @@ class EmptyStateTableViewController: UITableViewController, UIEmptyStateDelegate } var emptyStateTitle: NSAttributedString { - let attrs = [NSAttributedStringKey.foregroundColor: UIColor(red: 0.882, green: 0.890, blue: 0.859, alpha: 1.00), - NSAttributedStringKey.font: UIFont.systemFont(ofSize: 22)] + let attrs = [NSAttributedString.Key.foregroundColor: UIColor(red: 0.882, green: 0.890, blue: 0.859, alpha: 1.00), + NSAttributedString.Key.font: UIFont.systemFont(ofSize: 22)] return NSAttributedString(string: "No Pokemon caught!", attributes: attrs) } var emptyStateButtonTitle: NSAttributedString? { - let attrs = [NSAttributedStringKey.foregroundColor: UIColor.white, - NSAttributedStringKey.font: UIFont.systemFont(ofSize: 16)] + let attrs = [NSAttributedString.Key.foregroundColor: UIColor.white, + NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16)] return NSAttributedString(string: "Catch'em All", attributes: attrs) } @@ -83,7 +83,7 @@ class EmptyStateTableViewController: UITableViewController, UIEmptyStateDelegate return cell } - override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { + override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { // Delete the row tableView.beginUpdates() diff --git a/UIEmptyState/UIEmptyStateView.swift b/UIEmptyState/UIEmptyStateView.swift index 88db67e..978913c 100644 --- a/UIEmptyState/UIEmptyStateView.swift +++ b/UIEmptyState/UIEmptyStateView.swift @@ -270,7 +270,7 @@ open class UIEmptyStateView: UIView { private func handleAdding(view: UIView) { // The order we want is 1. Image View, 2. Title Label, 3. Detail Label, 4. Button // If already added we can return - if contentView.subviews.index(of: view) != nil { return } + if contentView.subviews.firstIndex(of: view) != nil { return } // Tags correspond to the views AND the order we want them in switch view.tag { diff --git a/UIEmptyState/UIViewController+UIEmptyState.swift b/UIEmptyState/UIViewController+UIEmptyState.swift index 65b2801..5b14dd6 100644 --- a/UIEmptyState/UIViewController+UIEmptyState.swift +++ b/UIEmptyState/UIViewController+UIEmptyState.swift @@ -218,7 +218,7 @@ extension UIViewController { // Add as a subView, bring it infront of the tableView self.emptyStateDataSource?.emptyStateContainerView.addSubview(newView) - self.emptyStateDataSource?.emptyStateContainerView.sendSubview(toBack: newView) + self.emptyStateDataSource?.emptyStateContainerView.sendSubviewToBack(newView) // Animate now if source.emptyStateViewCanAnimate { From 633c680324ee8bd951f3e557a99f10eb1c7757a7 Mon Sep 17 00:00:00 2001 From: Prashant Sihag Date: Mon, 8 Mar 2021 14:57:54 +0530 Subject: [PATCH 5/5] red color removed and font problem fixed --- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ UIEmptyState/UIEmptyStateView.swift | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 UIEmptyState.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/UIEmptyState.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/UIEmptyState.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/UIEmptyState.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/UIEmptyState/UIEmptyStateView.swift b/UIEmptyState/UIEmptyStateView.swift index 978913c..b0239d1 100644 --- a/UIEmptyState/UIEmptyStateView.swift +++ b/UIEmptyState/UIEmptyStateView.swift @@ -159,7 +159,7 @@ open class UIEmptyStateView: UIView { return } - detailLabel.attributedText = message + detailLabel.attributedText = NSAttributedString(string: message.string) self.setNeedsUpdateConstraints() handleAdding(view: detailLabel) } @@ -253,7 +253,7 @@ open class UIEmptyStateView: UIView { contentView.axis = .vertical contentView.distribution = .equalSpacing contentView.alignment = .center - contentView.backgroundColor = UIColor.red + contentView.backgroundColor = .clear contentView.spacing = spacing ?? 0 contentView.translatesAutoresizingMaskIntoConstraints = false contentView.addArrangedSubview(titleLabel)