Code Monkey home page Code Monkey logo

easyloadingshimmer's Introduction

EasyLoadingShimmer

这是一个网络请求页面加载等待的的框架,目前饿了么、京东等都是用此动态效果,接入方便快捷。

Installation

CocoaPods

The easiest way of installing EasyLoadingShimmer is via CocoaPods.

pod 'EasyLoadingShimmer'

Old-fashioned way

  • Add EasyLoadingShimmer.swift to your project.

Usage

Effect gif:

EasyLoadingShimmer

Demo:

  • 普通View视图添加loading
// 普通view视图
	// 在需要展示loading的地方
	EasyLoadingShimmer.startCovering(for: view)
	// 在需要隐藏loading的地方
	EasyLoadingShimmer.stopCovering(for: view)
  • UITableView中添加loading
	// UITableView中使用Demo	
	/* 步骤:
	①、设置全局变量numberOfSections、numberOfRows都为0
	②、创建UITableView并注册cell
	③、实现代理(使用步骤①中的变量)
	④、在需要展示loading的地方执行如下startLoading方法。
	*/

    lazy var tableView: UITableView = {
        let t = UITableView.init(frame: view.bounds, style: .plain)
        t.dataSource = self
        t.delegate = self
        t.estimatedRowHeight = 150
        t.rowHeight = 150
        t.register(CustomCell.self, forCellReuseIdentifier: "Cell1")
        return t
    }()

    var numberOfRows: Int =  0
    var numberOfSections: Int = 0

    override func viewDidAppear(_ animated: Bool) {
        // 传入注册cell的identifier,数组传几个就会在loading时显示几个cell,跟实际返回显示数据无关
        EasyLoadingShimmer.startCovering(for: tableView, with: ["Cell1", "Cell1", "Cell1", "Cell1", "Cell1"])
    }
    
    @objc func startLoading() {
        numberOfSections = 0
        numberOfRows = 0
        tableView.reloadData()
        EasyLoadingShimmer.startCovering(for: tableView, with: ["Cell1", "Cell1", "Cell1", "Cell1", "Cell1"])
    }

    @objc func stopLoading() {
        numberOfSections = 1
        numberOfRows = 10
        tableView.reloadData()
        EasyLoadingShimmer.stopCovering(for: tableView)
    }

If you have any questions, you can check the Demo.

License

EasyLoadingShimmer is licensed under the terms of the MIT License. Please see the LICENSE file for full details.

If this code was helpful, I would love to hear from you.

easyloadingshimmer's People

Contributors

wsj2012 avatar

Stargazers

 avatar

Watchers

James Cloos 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.