Git Product home page Git Product logo

trendingtechnology / wlemptystate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wizelinelabs/wlemptystate

0.0 3.0 0.0 248 KB

WLEmptyState is an iOS based component that lets you customize the view when the dataset of UITableView is empty. We created a sample project with the WLEmptyState component to show how you can use it.

Home Page: https://cocoapods.org/pods/WLEmptyState

License: MIT License

Ruby 12.80% Swift 87.20%

wlemptystate's Introduction

WLEmptyState_Banner Build Status Version Twitter

Table of Content

Overview

WLEmptyState is an iOS based component that lets you customize the message when the dataset of UITableView is empty. We created a sample project with the WLEmptyState component to show how you can use it.

Running an Example Project

To run the Example project:

  1. Clone the repo with the following command:

    git clone [email protected]:wizeline/WLEmptyState.git

  2. Move to the Example directory and run the following command:

    pod install

Installing WLEmptyState

WLEmptyState is available through CocoaPods. To install it, add the following command to your Podfile:

pod 'WLEmptyState'

Configuring WLEmptyState

The WLEmptyState component uses Method Swizzling. Therefore, to configure WLEmptyState, follow these steps:

  1. Import the module in the AppDelegate class by adding import WLEmptyState.

  2. Call the static method configure() on application(_ application:, didFinishLaunchingWithOptions:) method.

    Your AppDelegate class should look like this:

    import WLEmptyState
        ...
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        WLEmptyState.configure()
        return true
    }

Using WLEmptyState

Once you have configured WLEmptyState, you can use it for your UITableViewController. You need to conform the WLEmptyStateDataSource protocol. For example,

class YourTableViewController: UITableViewController, WLEmptyStateDataSource {

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.emptyStateDataSource = self
    }

}

After you run your project with an empty dataset for a table, you'll be able to see a default WLEmptyState view.

Default Image

Default WLEmptyState

Customizing WLEmptyState

If you want to customize the text, description, or image, you need to implement the WLEmptyStateDataSource function. You can find the code for customization in the following list:

  • Customize Image
func imageForEmptyDataSet() -> UIImage? {
    return UIImage(named: "bubble_icon")
}
  • Customize Title
func titleForEmptyDataSet() -> NSAttributedString {
    let title = NSAttributedString(string: "No messages", attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)])
    return title
}
  • Customize Description
func descriptionForEmptyDataSet() -> NSAttributedString {
    let title = NSAttributedString(string: "There's no messages to show.", attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .caption1)])
    return title
}

Customized Image

Contributing to WLEmptyState

We actively welcome your pull requests. We are trying to make contributions to this project as transparent and accessible as possible, please read our Contributing guidelines and follow the Code of conduct. If you face any problem with the code, please open an issue on GitHub.

List of Contributors. ⭐️

License

WLEmptyState is available under the MIT license. See the LICENSE file for more info.

wlemptystate's People

Contributors

alexandercg avatar leonardo-garcia avatar lojals avatar p-daemon avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.