显示UITableView占位符 - HGPlaceholders

2017-07-21      808      Swift
项目简介

HGPlaceholders

Example

To run the example project, clone the repo, and runpod installfrom the Example directory first.

Requirements

  • iOS 9.0+
  • Xcode 8.0

Installation

HGPlaceholders is available through CocoaPods . To install it, simply add the following line to your Podfile:

# Swift 3.1 - Xcode 8.3
pod "HGPlaceholders"

HGCircularSlider is also available through Carthage . To install it, simply add the following line to your Cartfile:

github "HamzaGhazouani/HGPlaceholders"

Usage

  1. Inherit your UITableView class from TableView
  2. Call the placeholder to show
  • tableView.showLoadingPlaceholder()
  • tableView.showNoResultsPlaceholder()
  • tableView.showErrorPlaceholder()
  • tableView.showNoConnectionPlaceholder()

Customization

If you want to change only images, just set them in your asset with this names (the framework check firstly in the main bundle):

  • loading : "hg_default-loading"
  • no_connection : "hg_default-no_connection"
  • no_results : "hg_default-no_results"
  • error : "hg_default-error"

The framework contains different defaults placeholders:

  • Basic :

tableView.placeholdersProvider = .basic

  • Default :

tableView.placeholdersProvider = .default

  • Default2 :

tableView.placeholdersProvider = .default2

  • Hallowen :

tableView.placeholdersProvider = .halloween // for fun :)

If you want to change the default palceholders for all table views in your project:

class ProjectNameTableView: TableView {

    override func customSetup() {
        placeholdersProvider = .basic
    }
}

You can also add new placeholders fully customizable, you should keep en mind that the view will take table view frame, and placeholder can have only one action, please check the example project