### Install EmptyDataSet-Swift with CocoaPods Source: https://github.com/xiaoye220/emptydataset-swift/blob/master/README.md This snippet shows how to add the EmptyDataSet-Swift library to your project using CocoaPods. Ensure you have CocoaPods installed and configured. ```bash pod 'EmptyDataSet-Swift', '~> 5.0.0' ``` -------------------------------- ### Install EmptyDataSet-Swift with Carthage Source: https://github.com/xiaoye220/emptydataset-swift/blob/master/README.md This snippet demonstrates how to integrate EmptyDataSet-Swift into your project using Carthage. Carthage is a decentralized dependency manager for macOS and iOS. ```bash github "Xiaoye220/EmptyDataSet-Swift" "4.2.0" ``` -------------------------------- ### Example Usage of Empty Data Set Extension Source: https://github.com/xiaoye220/emptydataset-swift/blob/master/README.md Demonstrates how to use the `emptyDataSetView` extension to configure an empty data set for a `tableView`. This example showcases setting various properties such as title, detail, image, button titles and backgrounds, colors, offsets, and event handlers for taps. It also includes options for controlling display, fading, and touch/scroll interactions. ```swift tableView.emptyDataSetView { view in view.titleLabelString(titleString) .detailLabelString(detailString) .image(image) .imageAnimation(imageAnimation) .buttonTitle(buttonTitle, for: .normal) .buttonTitle(buttonTitle, for: .highlighted) .buttonBackgroundImage(buttonBackgroundImage, for: .normal) .buttonBackgroundImage(buttonBackgroundImage, for: .highlighted) .dataSetBackgroundColor(backgroundColor) .verticalOffset(verticalOffset) .verticalSpace(spaceHeight) .shouldDisplay(true, view: tableView) .shouldFadeIn(true) .isTouchAllowed(true) .isScrollAllowed(true) .isImageViewAnimateAllowed(isLoading) .didTapDataButton { // Do something } .didTapContentView { // Do something } } ``` -------------------------------- ### Install EmptyDataSet-Swift with Swift Package Manager Source: https://context7.com/xiaoye220/emptydataset-swift/llms.txt This snippet demonstrates how to integrate EmptyDataSet-Swift into your project using the Swift Package Manager. Add the package URL to your Xcode project's Package Dependencies. ```swift dependencies: [ .package(url: "https://github.com/Xiaoye220/EmptyDataSet-Swift.git", from: "5.0.0") ] ``` -------------------------------- ### Install EmptyDataSet-Swift with CocoaPods Source: https://context7.com/xiaoye220/emptydataset-swift/llms.txt This snippet shows how to add EmptyDataSet-Swift to your project using CocoaPods. Ensure you have CocoaPods installed and a Podfile in your project's root directory. ```ruby # Podfile pod 'EmptyDataSet-Swift', '~> 5.0.0' ``` -------------------------------- ### Basic Usage of EmptyDataSet-Swift in Swift Source: https://github.com/xiaoye220/emptydataset-swift/blob/master/README.md This Swift code demonstrates the basic setup for using EmptyDataSet-Swift. It involves conforming your view controller to EmptyDataSetSource and EmptyDataSetDelegate, and assigning these to your table view or collection view. ```swift import EmptyDataSet_Swift class OriginalUsageViewController: UITableViewController, EmptyDataSetSource, EmptyDataSetDelegate { override func viewDidLoad() { super.viewDidLoad() tableView.emptyDataSetSource = self tableView.emptyDataSetDelegate = self } } ``` -------------------------------- ### Custom View and Vertical Offset for Empty Data Set (Swift) Source: https://github.com/xiaoye220/emptydataset-swift/blob/master/README.md This example shows how to combine a custom view with a vertical offset for an empty data set. The `verticalOffset(forEmptyDataSet:)` method or the `.verticalOffset()` modifier in the closure allows you to adjust the vertical position of the empty data set content. This is useful for fine-tuning the layout. ```swift func customView(forEmptyDataSet scrollView: UIScrollView) -> UIView? { let view = CustomView(frame: CGRect(x: 0, y: 0, width: 150, height: 150)) return view } func verticalOffset(forEmptyDataSet scrollView: UIScrollView) -> CGFloat { return 200 } ``` ```swift tableView.emptyDataSetView { [weak self] view in view.customView(CustomView(frame: CGRect(x: 0, y: 0, width: 150, height: 150))) .verticalOffset(200) } ``` -------------------------------- ### Protocol-Based Empty State Configuration in Swift Source: https://context7.com/xiaoye220/emptydataset-swift/llms.txt This Swift code demonstrates how to use the `EmptyDataSetSource` and `EmptyDataSetDelegate` protocols to configure and manage empty states for a `UITableView`. It covers setting titles, descriptions, images, button titles, background colors, offsets, and handling tap events. ```swift import UIKit import EmptyDataSet_Swift class MyTableViewController: UITableViewController, EmptyDataSetSource, EmptyDataSetDelegate { var items: [String] = [] override func viewDidLoad() { super.viewDidLoad() // Assign source and delegate tableView.emptyDataSetSource = self tableView.emptyDataSetDelegate = self tableView.tableFooterView = UIView() } // MARK: - UITableViewDataSource override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return items.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) cell.textLabel?.text = items[indexPath.row] return cell } // MARK: - EmptyDataSetSource func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? { let attributes: [NSAttributedString.Key: Any] = [ .font: UIFont.boldSystemFont(ofSize: 18), .foregroundColor: UIColor.darkGray ] return NSAttributedString(string: "No Items Found", attributes: attributes) } func description(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? { let attributes: [NSAttributedString.Key: Any] = [ .font: UIFont.systemFont(ofSize: 14), .foregroundColor: UIColor.lightGray ] return NSAttributedString(string: "Start by adding some items to your list.", attributes: attributes) } func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? { return UIImage(named: "empty_placeholder") } func buttonTitle(forEmptyDataSet scrollView: UIScrollView, for state: UIControl.State) -> NSAttributedString? { let attributes: [NSAttributedString.Key: Any] = [ .font: UIFont.boldSystemFont(ofSize: 16), .foregroundColor: state == .normal ? UIColor.systemBlue : UIColor.systemBlue.withAlphaComponent(0.5) ] return NSAttributedString(string: "Add Item", attributes: attributes) } func backgroundColor(forEmptyDataSet scrollView: UIScrollView) -> UIColor? { return UIColor.systemBackground } func verticalOffset(forEmptyDataSet scrollView: UIScrollView) -> CGFloat { return -50.0 // Offset content upward } func spaceHeight(forEmptyDataSet scrollView: UIScrollView) -> CGFloat { return 20.0 // Space between elements } // MARK: - EmptyDataSetDelegate func emptyDataSetShouldDisplay(_ scrollView: UIScrollView) -> Bool { return true } func emptyDataSetShouldAllowTouch(_ scrollView: UIScrollView) -> Bool { return true } func emptyDataSetShouldAllowScroll(_ scrollView: UIScrollView) -> Bool { return true } func emptyDataSet(_ scrollView: UIScrollView, didTapButton button: UIButton) { // Handle button tap - add new item items.append("New Item (items.count + 1)") tableView.reloadData() } func emptyDataSet(_ scrollView: UIScrollView, didTapView view: UIView) { // Handle view tap print("Empty state view tapped") } } ``` -------------------------------- ### EmptyDataSetSource Protocol Definition Source: https://github.com/xiaoye220/emptydataset-swift/blob/master/README.md Defines the data source interface for configuring empty data sets. It includes methods for setting title, description, image, button titles, background colors, custom views, and layout offsets. Conforming to this protocol allows a class to provide all necessary information for displaying an empty state. ```swift public protocol EmptyDataSetSource: class { /// Asks the data source for the title of the dataset. /// The dataset uses a fixed font style by default, if no attributes are set. If you want a different font style, return a attributed string. func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? /// Asks the data source for the description of the dataset. /// The dataset uses a fixed font style by default, if no attributes are set. If you want a different font style, return a attributed string. func description(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? /// Asks the data source for the image of the dataset. func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? /// Asks the data source for a tint color of the image dataset. Default is nil. func imagetintColor(forEmptyDataSet scrollView: UIScrollView) -> UIColor? /// Asks the data source for the image animation of the dataset. func imageAnimation(forEmptyDataSet scrollView: UIScrollView) -> CAAnimation? /// Asks the data source for the title to be used for the specified button state. /// The dataset uses a fixed font style by default, if no attributes are set. If you want a different font style, return a attributed string. func buttonTitle(forEmptyDataSet scrollView: UIScrollView, for state: UIControl.State) -> NSAttributedString? /// Asks the data source for the image to be used for the specified button state. /// This method will override buttonTitleForEmptyDataSet:forState: and present the image only without any text. func buttonImage(forEmptyDataSet scrollView: UIScrollView, for state: UIControl.State) -> UIImage? /// Asks the data source for a background image to be used for the specified button state. /// There is no default style for this call. func buttonBackgroundImage(forEmptyDataSet scrollView: UIScrollView, for state: UIControl.State) -> UIImage? /// Asks the data source for the background color of the dataset. Default is clear color. func backgroundColor(forEmptyDataSet scrollView: UIScrollView) -> UIColor? /// Asks the data source for a custom view to be displayed instead of the default views such as labels, imageview and button. Default is nil. /// Use this method to show an activity view indicator for loading feedback, or for complete custom empty data set. /// Returning a custom view will ignore -offsetForEmptyDataSet and -spaceHeightForEmptyDataSet configurations. func customView(forEmptyDataSet scrollView: UIScrollView) -> UIView? /// Asks the data source for a offset for vertical alignment of the content. Default is 0. func verticalOffset(forEmptyDataSet scrollView: UIScrollView) -> CGFloat /// Asks the data source for a vertical space between elements. Default is 11 pts. func spaceHeight(forEmptyDataSet scrollView: UIScrollView) -> CGFloat } ``` -------------------------------- ### EmptyDataSet View Extensions Source: https://github.com/xiaoye220/emptydataset-swift/blob/master/README.md Extensions provide a convenient way to configure the empty data set using a closure, without explicitly conforming to the `EmptyDataSetSource` protocol. This allows for dynamic setting of properties like title, detail, image, and actions. ```APIDOC ## EmptyDataSet View Extensions ### Description These extensions allow you to configure the empty data set directly on a scroll view using a closure, providing a more fluent API for setting various properties and handling user interactions. ### Method - **`emptyDataSetView(_:)`**: A closure that is executed to configure the `EmptyDataSetView`. ### Usage Example ```swift tableView.emptyDataSetView { view in view.titleLabelString(titleString) .detailLabelString(detailString) .image(image) .imageAnimation(imageAnimation) .buttonTitle(buttonTitle, for: .normal) .buttonBackgroundImage(buttonBackgroundImage, for: .normal) .dataSetBackgroundColor(backgroundColor) .verticalOffset(verticalOffset) .verticalSpace(spaceHeight) .shouldDisplay(true, view: tableView) .shouldFadeIn(true) .isTouchAllowed(true) .isScrollAllowed(true) .isImageViewAnimateAllowed(isLoading) .didTapDataButton { /* Action for data button tap */ } .didTapContentView { /* Action for content view tap */ } } ``` ### About CustomView - When using `customView` via `EmptyDataSetSource`, other settings will be invalid. - When using `customView` via Extensions, other autolayout configurations will be invalid. **Rule for displaying CustomView:** 1. CustomView will be displayed in the center of the tableView. 2. The `verticalOffset` of customView can be set using `func verticalOffset(forEmptyDataSet scrollView: UIScrollView) -> CGFloat`. 3. The width and height are equal to the frame of `customView`. If `customView` is a `UILabel` and its frame is `CGRect.zero`, its width and height will be autolayout based on its content. ``` -------------------------------- ### Custom View for Empty Data Set (Swift) Source: https://github.com/xiaoye220/emptydataset-swift/blob/master/README.md This snippet demonstrates how to provide a completely custom view to be displayed when a data set is empty. It involves implementing the `customView(forEmptyDataSet:)` method or using the `emptyDataSetView` closure with a custom view instance. This allows for full control over the UI presented to the user. ```swift func customView(forEmptyDataSet scrollView: UIScrollView) -> UIView? { let view = CustomView(frame: CGRect(x: 0, y: 0, width: 150, height: 150)) return view } ``` ```swift tableView.emptyDataSetView { [weak self] view in view.customView(CustomView(frame: CGRect(x: 0, y: 0, width: 150, height: 150))) } ``` -------------------------------- ### Text-Based Custom View for Empty Data Set (Swift) Source: https://github.com/xiaoye220/emptydataset-swift/blob/master/README.md This snippet illustrates creating a custom view for an empty data set using a simple `UILabel`. This approach is suitable when you only need to display text, potentially with custom styling like background color, without requiring a complex view hierarchy. It's a straightforward way to provide informative messages. ```swift func customView(forEmptyDataSet scrollView: UIScrollView) -> UIView? { let label = UILabel() label.text = "CustomView" label.backgroundColor = UIColor.red return label } ``` -------------------------------- ### Implement Custom Empty State View in Swift Source: https://context7.com/xiaoye220/emptydataset-swift/llms.txt This Swift code snippet shows how to create a custom view for empty data states using the EmptyDataSet-Swift library. It handles displaying a loading indicator while data is being fetched and a fully customized view with an image, text, and button when data is available but empty. This requires the EmptyDataSet-Swift library and UIKit. ```swift import UIKit import EmptyDataSet_Swift class CustomEmptyStateViewController: UITableViewController, EmptyDataSetSource, EmptyDataSetDelegate { var isLoading = true var items: [String] = [] override func viewDidLoad() { super.viewDidLoad() tableView.emptyDataSetSource = self tableView.emptyDataSetDelegate = self // Simulate data loading DispatchQueue.main.asyncAfter(deadline: .now() + 3) { self.isLoading = false self.tableView.reloadEmptyDataSet() } } // MARK: - EmptyDataSetSource func customView(forEmptyDataSet scrollView: UIScrollView) -> UIView? { if isLoading { // Show loading spinner let activityIndicator = UIActivityIndicatorView(style: .large) activityIndicator.color = .systemBlue activityIndicator.startAnimating() return activityIndicator } else { // Show custom empty view let customView = UIView(frame: CGRect(x: 0, y: 0, width: 250, height: 200)) let imageView = UIImageView(image: UIImage(named: "custom_empty")) imageView.frame = CGRect(x: 75, y: 0, width: 100, height: 100) imageView.contentMode = .scaleAspectFit customView.addSubview(imageView) let label = UILabel(frame: CGRect(x: 0, y: 110, width: 250, height: 40)) label.text = "Nothing to see here" label.textAlignment = .center label.font = UIFont.systemFont(ofSize: 18, weight: .medium) label.textColor = .darkGray customView.addSubview(label) let button = UIButton(type: .system) button.frame = CGRect(x: 50, y: 160, width: 150, height: 40) button.setTitle("Get Started", for: .normal) button.backgroundColor = .systemBlue button.setTitleColor(.white, for: .normal) button.layer.cornerRadius = 8 customView.addSubview(button) return customView } } // MARK: - UITableViewDataSource override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return items.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) cell.textLabel?.text = items[indexPath.row] return cell } } ``` -------------------------------- ### EmptyDataSetSource Protocol Source: https://github.com/xiaoye220/emptydataset-swift/blob/master/README.md The `EmptyDataSetSource` protocol defines the methods that a data source must implement to provide content for an empty data set. This includes titles, descriptions, images, buttons, background colors, and custom views. ```APIDOC ## EmptyDataSetSource Protocol ### Description The `EmptyDataSetSource` protocol provides methods to configure the content and appearance of an empty data set displayed in a scroll view. ### Methods - **`title(forEmptyDataSet:)`**: Returns the title for the empty data set as an `NSAttributedString`. - **`description(forEmptyDataSet:)`**: Returns the description for the empty data set as an `NSAttributedString`. - **`image(forEmptyDataSet:)`**: Returns the image to be displayed in the empty data set. - **`imagetintColor(forEmptyDataSet:)`**: Returns the tint color for the empty data set image. - **`imageAnimation(forEmptyDataSet:)`**: Returns a `CAAnimation` for the empty data set image. - **`buttonTitle(forEmptyDataSet:for:)`**: Returns the title for a button in the empty data set for a specific control state. - **`buttonImage(forEmptyDataSet:for:)`**: Returns the image for a button in the empty data set for a specific control state. - **`buttonBackgroundImage(forEmptyDataSet:for:)`**: Returns the background image for a button in the empty data set for a specific control state. - **`backgroundColor(forEmptyDataSet:)`**: Returns the background color for the empty data set. - **`customView(forEmptyDataSet:)`**: Returns a custom `UIView` to be displayed instead of the default content. - **`verticalOffset(forEmptyDataSet:)`**: Returns the vertical offset for the content of the empty data set. - **`spaceHeight(forEmptyDataSet:)`**: Returns the vertical space between elements in the empty data set. ``` -------------------------------- ### Configure Empty Data Set with Closures in Swift Source: https://context7.com/xiaoye220/emptydataset-swift/llms.txt Configures the empty data set view using a closure-based API for a UITableView. This approach allows for method chaining to set various properties like title, detail text, image, button, background color, and interaction behaviors. It requires the EmptyDataSet-Swift library. ```swift import UIKit import EmptyDataSet_Swift class ModernTableViewController: UITableViewController { var items: [String] = [] var isLoading = false { didSet { tableView.reloadEmptyDataSet() } } override func viewDidLoad() { super.viewDidLoad() tableView.tableFooterView = UIView() // Configure empty data set using closure-based API with method chaining tableView.emptyDataSetView { [weak self] view in guard let self = self else { return } view.titleLabelString(NSAttributedString( string: "No Data Available", attributes: [ .font: UIFont.boldSystemFont(ofSize: 20), .foregroundColor: UIColor.darkGray ] )) .detailLabelString(NSAttributedString( string: "Pull to refresh or tap to reload.", attributes: [ .font: UIFont.systemFont(ofSize: 14), .foregroundColor: UIColor.gray ] )) .image(UIImage(named: "empty_state_icon")) .imageTintColor(UIColor.systemBlue) .buttonTitle(NSAttributedString( string: "Reload", attributes: [ .font: UIFont.boldSystemFont(ofSize: 16), .foregroundColor: UIColor.white ] ), for: .normal) .buttonBackgroundImage(UIImage(named: "button_background"), for: .normal) .dataSetBackgroundColor(UIColor.systemGroupedBackground) .verticalOffset(-30) .verticalSpace(15) .shouldFadeIn(true) .shouldDisplay(true) .isTouchAllowed(true) .isScrollAllowed(true) .isImageViewAnimateAllowed(self.isLoading) .didTapContentView { self.refreshData() } .didTapDataButton { self.refreshData() } .willAppear { print("Empty data set will appear") } .didAppear { print("Empty data set did appear") } } } func refreshData() { isLoading = true DispatchQueue.main.asyncAfter(deadline: .now() + 2) { self.isLoading = false // Simulate data fetch self.items = ["Item 1", "Item 2", "Item 3"] self.tableView.reloadData() } } // MARK: - UITableViewDataSource override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return items.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) cell.textLabel?.text = items[indexPath.row] return cell } } ``` -------------------------------- ### Empty Data Set Configuration Extension Source: https://github.com/xiaoye220/emptydataset-swift/blob/master/README.md Provides a convenient extension for configuring empty data sets on `UIScrollView`. It allows setting various properties like title, detail, image, button titles, and background colors using a closure-based syntax. This extension simplifies the process of customizing the empty state appearance and behavior. ```swift public func emptyDataSetView(_ closure: @escaping (EmptyDataSetView) -> Void) ``` -------------------------------- ### Custom View Display Rules for Empty Data Sets Source: https://github.com/xiaoye220/emptydataset-swift/blob/master/README.md Explains the rules for displaying a custom view within an empty data set. When a custom view is provided via `EmptyDataSetSource` or the extensions, it takes precedence over default views. The custom view is centered, and its position can be adjusted using `verticalOffset`. Its size is determined by its frame, with special handling for `UILabel`s. ```swift // Rule for displaying CustomView: // 1. CustomView will Display in the center of tableView // 2. The verticalOffset of customView can be setted by ```func verticalOffset(forEmptyDataSet scrollView: UIScrollView) -> CGFloat``` // 3. The width and height is equel to the frame of customView.But if the customView is UILabel and it's frame is CGRect.zero,it's width and height will be autolayout by it's content. ``` -------------------------------- ### Manual Reload and Visibility Check in Swift Source: https://context7.com/xiaoye220/emptydataset-swift/llms.txt This Swift code snippet shows how to manually reload the empty data set and check its visibility. It simulates fetching data, encountering an error, and then explicitly reloading the empty state to display the error message. It also includes a function to check if the empty data set is currently visible on the screen. ```swift import UIKit import EmptyDataSet_Swift class ManualReloadViewController: UITableViewController, EmptyDataSetSource { var items: [String] = [] var errorMessage: String? override func viewDidLoad() { super.viewDidLoad() tableView.emptyDataSetSource = self } func fetchData() { // Simulate API call DispatchQueue.main.asyncAfter(deadline: .now() + 1) { // Simulate error self.errorMessage = "Network connection failed" self.items = [] // Manually reload empty data set to show error state self.tableView.reloadEmptyDataSet() } } func checkEmptyStateVisibility() { // Check if empty data set is currently visible if tableView.isEmptyDataSetVisible { print("Empty state is being displayed") } else { print("Table has content") } } // MARK: - EmptyDataSetSource func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? { if let error = errorMessage { return NSAttributedString( string: "Error", attributes: [.foregroundColor: UIColor.systemRed] ) } return NSAttributedString(string: "No Items") } func description(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? { if let error = errorMessage { return NSAttributedString( string: error, attributes: [.foregroundColor: UIColor.gray] ) } return NSAttributedString(string: "Add items to get started") } // MARK: - UITableViewDataSource override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return items.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) cell.textLabel?.text = items[indexPath.row] return cell } } ``` -------------------------------- ### EmptyDataSetDelegate Protocol Definition in Swift Source: https://github.com/xiaoye220/emptydataset-swift/blob/master/README.md This Swift code defines the EmptyDataSetDelegate protocol, which allows you to customize the behavior and appearance of the empty dataset. It includes methods for controlling display, animations, and handling user interactions like taps. ```swift public protocol EmptyDataSetDelegate: class { /// Asks the delegate to know if the empty dataset should fade in when displayed. Default is true. func emptyDataSetShouldFadeIn(_ scrollView: UIScrollView) -> Bool /// Asks the delegate to know if the empty dataset should still be displayed when the amount of items is more than 0. Default is false. func emptyDataSetShouldBeForcedToDisplay(_ scrollView: UIScrollView) -> Bool /// Asks the delegate to know if the empty dataset should be rendered and displayed. Default is true. func emptyDataSetShouldDisplay(_ scrollView: UIScrollView) -> Bool /// Asks the delegate for touch permission. Default is true. func emptyDataSetShouldAllowTouch(_ scrollView: UIScrollView) -> Bool /// Asks the delegate for scroll permission. Default is false. func emptyDataSetShouldAllowScroll(_ scrollView: UIScrollView) -> Bool /// Asks the delegate for image view animation permission. Default is false. /// Make sure to return a valid CAAnimation object from imageAnimationForEmptyDataSet: func emptyDataSetShouldAnimateImageView(_ scrollView: UIScrollView) -> Bool /// Tells the delegate that the empty dataset view was tapped. /// Use this method either to resignFirstResponder of a textfield or searchBar. func emptyDataSet(_ scrollView: UIScrollView, didTapView view: UIView) /// Tells the delegate that the action button was tapped. func emptyDataSet(_ scrollView: UIScrollView, didTapButton button: UIButton) /// Tells the delegate that the empty data set will appear. func emptyDataSetWillAppear(_ scrollView: UIScrollView) /// Tells the delegate that the empty data set did appear. func emptyDataSetDidAppear(_ scrollView: UIScrollView) /// Tells the delegate that the empty data set will disappear. func emptyDataSetWillDisappear(_ scrollView: UIScrollView) /// Tells the delegate that the empty data set did disappear. func emptyDataSetDidDisappear(_ scrollView: UIScrollView) } ``` -------------------------------- ### Animated Image for Loading States in UITableView with Swift Source: https://context7.com/xiaoye220/emptydataset-swift/llms.txt Implements an animated image for loading states within a UITableView's empty data set using EmptyDataSet-Swift. This allows for visual feedback during data loading. It requires the EmptyDataSet-Swift library, UIKit, and Core Animation. ```swift import UIKit import EmptyDataSet_Swift class AnimatedEmptyStateViewController: UITableViewController, EmptyDataSetSource, EmptyDataSetDelegate { var isLoading = false { didSet { tableView.reloadEmptyDataSet() } } override func viewDidLoad() { super.viewDidLoad() tableView.emptyDataSetSource = self tableView.emptyDataSetDelegate = self } // MARK: - EmptyDataSetSource func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? { let text = isLoading ? "Loading..." : "No Data" return NSAttributedString(string: text, attributes: [.font: UIFont.boldSystemFont(ofSize: 18)]) } func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? { return UIImage(named: isLoading ? "loading_spinner" : "empty_icon") } func imageAnimation(forEmptyDataSet scrollView: UIScrollView) -> CAAnimation? { // Create rotation animation for loading state let animation = CABasicAnimation(keyPath: "transform.rotation.z") animation.fromValue = 0 animation.toValue = Double.pi * 2 animation.duration = 1.0 animation.repeatCount = .infinity animation.isRemovedOnCompletion = false return animation } // MARK: - EmptyDataSetDelegate func emptyDataSetShouldAnimateImageView(_ scrollView: UIScrollView) -> Bool { return isLoading // Only animate when loading } func emptyDataSet(_ scrollView: UIScrollView, didTapView view: UIView) { // Start loading when tapped isLoading = true DispatchQueue.main.asyncAfter(deadline: .now() + 3) { self.isLoading = false } } // MARK: - UITableViewDataSource override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 0 } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { return UITableViewCell() } } ``` -------------------------------- ### UICollectionView Empty State Configuration with Swift Source: https://context7.com/xiaoye220/emptydataset-swift/llms.txt Configures an empty state for a UICollectionView using the EmptyDataSet-Swift library. It sets custom text, an icon, and a button action for when the collection view has no data. This requires the EmptyDataSet-Swift library and UIKit. ```swift import UIKit import EmptyDataSet_Swift class PhotoCollectionViewController: UICollectionViewController, EmptyDataSetSource, EmptyDataSetDelegate { var photos: [UIImage] = [] override func viewDidLoad() { super.viewDidLoad() collectionView.emptyDataSetSource = self collectionView.emptyDataSetDelegate = self } // MARK: - UICollectionViewDataSource override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return photos.count } override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PhotoCell", for: indexPath) // Configure cell return cell } // MARK: - EmptyDataSetSource func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? { return NSAttributedString( string: "No Photos", attributes: [ .font: UIFont.boldSystemFont(ofSize: 22), .foregroundColor: UIColor.label ] ) } func description(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? { return NSAttributedString( string: "Take or upload photos to see them here.", attributes: [ .font: UIFont.systemFont(ofSize: 16), .foregroundColor: UIColor.secondaryLabel ] ) } func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? { return UIImage(systemName: "photo.on.rectangle.angled") } func imageTintColor(forEmptyDataSet scrollView: UIScrollView) -> UIColor? { return UIColor.systemGray } func buttonTitle(forEmptyDataSet scrollView: UIScrollView, for state: UIControl.State) -> NSAttributedString? { return NSAttributedString( string: "Take Photo", attributes: [ .font: UIFont.systemFont(ofSize: 16, weight: .semibold), .foregroundColor: UIColor.systemBlue ] ) } // MARK: - EmptyDataSetDelegate func emptyDataSet(_ scrollView: UIScrollView, didTapButton button: UIButton) { // Open camera let picker = UIImagePickerController() picker.sourceType = .camera present(picker, animated: true) } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.