https://github.com/eneskaraosman/swiftemptystate
Displaying Empty state of a page. (UIKit)
https://github.com/eneskaraosman/swiftemptystate
cocoapods empty-state ios swift swiftpackagemanager
Last synced: 10 months ago
JSON representation
Displaying Empty state of a page. (UIKit)
- Host: GitHub
- URL: https://github.com/eneskaraosman/swiftemptystate
- Owner: EnesKaraosman
- License: mit
- Created: 2020-02-25T08:22:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-28T07:41:17.000Z (over 6 years ago)
- Last Synced: 2025-04-19T05:24:08.465Z (about 1 year ago)
- Topics: cocoapods, empty-state, ios, swift, swiftpackagemanager
- Language: Swift
- Homepage:
- Size: 3.62 MB
- Stars: 11
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftEmptyState
[](https://travis-ci.org/eneskaraosman/SwiftEmptyState)
[](https://cocoapods.org/pods/SwiftEmptyState)
[](https://cocoapods.org/pods/SwiftEmptyState)
[](https://cocoapods.org/pods/SwiftEmptyState)
## Demo

## Why do I need?
Common usage case;
**TLDR**;
Image you're getting data from a backend, your request succeded but it is just an empty list.
Don't left user with a blank screen, or boring alerts.
[Display Empty State - Medium Blog](https://medium.com/mobiletech/display-empty-state-of-a-page-in-ios-aa2430ac7d58)
## Usage
For better understanding, please view Example project.
To run the example project, clone the repo, and run `pod install` from the Example directory first.
But here below the main concept.
Usable in any `UITableViewController`, `UICollectionViewController` and `UIViewController`
```swift
class TableViewController: UITableViewController {
lazy var emptyStateManager: EmptyStateManager = {
let esv = EmptyStateView(
messageText: "This is label belongs to empty state view that sits in UITableViewController's UITableView",
titleText: "EmptyState Title",
image: UIImage(named: "empty_state_image"),
buttonText: "Button",
centerYOffset: -100 // In case you want to move it to top, by default it is centered (offset = 0)
)
esv.buttonAction = { _ in
esv.messageText = "Button action works 👍🏻"
}
let manager = EmptyStateManager(
containerView: self.tableView,
emptyView: esv,
animationConfiguration: .init(animationType: .spring)
)
return manager
}()
var dataSource = (1...50).map { _ in UIColor.random } {
didSet {
self.tableView.reloadData()
self.emptyStateManager.reloadState()
}
}
// dataSource is the dataSource of tableView
}
```
Same example valid for UICollectionView contentView,
If your content view is subclass of `ICollectionView/UITableView`
manager knows whether it hasContent, but in case you use pure UIView as contentView
then make sure you set hasContent manually.
```swift
manager.hasContent = {
!self.dataSource.isEmpty
}
```
## Animation
`EmptyStateManager` has animationConfiguration parameter with default values.
```swift
struct AnimationConfiguration {
let animationType: AnimationType // .spring, .fromBottom, .fromLeft, .fromTop, .fromRight
let animationDuration: TimeInterval
let subItemDelayConstant: Double // image, titleLabel, messageLabel, button. Except .spring animation
let springDamping: CGFloat // .spring animation case
let initialVelocity: CGFloat
let options: UIView.AnimationOptions
}
let manager = EmptyStateManager(
containerView: ***,
emptyView: ***,
animationConfiguration: .init(animationType: .spring)
)
```
## Customization
If you want to make your custom EmptyStateView
Just implement `IEmptyStateView` protocol in your custom UIView class.
## Requirements
iOS 10+
Swift 5+
## Installation
#### Pod
SwiftEmptyState is available through [CocoaPods](https://cocoapods.org). To install
it, simply add the following line to your Podfile:
```ruby
pod 'SwiftEmptyState'
```
#### Package Manager
Add new package from repository link: https://github.com/EnesKaraosman/SwiftEmptyState.git
## Author
eneskaraosman, eneskaraosman53@gmail.com
## License
SwiftEmptyState is available under the MIT license. See the LICENSE file for more info.