Giter VIP home page Giter VIP logo

wynullview's Introduction

WYNullView

An easy way to use when view' content is empty

Overview

How to use

  • Installation with CocoaPods:pod 'WYNullView'

  • Import the main file:#import "WYNullView.h"

  • On the empty state show default content, then all you have to do is:

if (showNullView) { // 无数据,empty data -》 show nullview
  [self.tableView wy_showNullView];
} else { // 有数据,data -》 hide nullview
  [self.tableView wy_hideNullView];
}
  • You will be able to fully customize the content and appearance of the empty states for your application
if (showNullView) { // 无数据,empty data -》 show nullview
  [self.tableView wy_showNullView:^UIView *(NullView *defaultNullView) {
     // you can do any constom operation in this block, even return a new constom UIView obj 
     // rerurn [UIView new];
     defaultNullView.desText = @"基于NullView自定义";
     defaultNullView.frame = CGRectMake(10, 10, defaultNullView.frame.size.width, defaultNullView.frame.size.height);
     defaultNullView.backgroundColor = [UIColor cyanColor];
     return defaultNullView;
  } heightOffset:0.0];
} else { // 有数据,data -》 hide nullview
  [self.tableView wy_hideNullView];
}

Implementation

  • UIView-Category add AssociatedObject "wy_nullView":
///> 空视图
@property (nonatomic, strong) UIView *wy_nullView;
  • Looking for NullView chain:

    • + (void)wy_configGlobleNullView:(NullViewHandle)nullViewHandle
    • - (void)wy_configNullView:(NullViewHandle)nullViewHandle
    • - (void)wy_showNullView:(NullViewHandle)nullViewHandle heightOffset:(CGFloat)offset
  • NullViewHandle Type:

typedef UIView *(^NullViewHandle)(NullView *defaultNullView);
  • Different methods can be used in different ways:

    • Global configuration 【View object whatever it is type, show the same content from "wy_configGlobleNullView" nullViewHandle return 】:
     [UIView wy_configGlobleNullView:^UIView *(NullView *defaultNullView) {
        // return globalNullView...
     }];
    • View configuration【Once config, you can call "wy_showNullView" directly, 】
     - (void)viewDidLoad {
       [mView wy_configNullView:^UIView *(NullView *defaultNullView) {
          // return nullView...
       }];
     }
     - (void)func1 {
       ...
       [mView wy_showNullView];
       ...
     }
     - (void)func2 {
       ...
       [mView wy_showNullView];
       ...
     }
    • If you have plenty of time, you can do the following【Equivalent to the above】:
     		
     - (void)func1 {
       ...
       [mView wy_showNullView:^UIView *(NullView *defaultNullView) {
          // return nullView...
       } heightOffset:0.0]];
       ...
     }
     - (void)func2 {
       ...
       [mView wy_showNullView:^UIView *(NullView *defaultNullView) {
         // return nullView...
        } heightOffset:0.0]];
       ...
     }
  • Control special subView show/hidden

    • filter obj
     // add objc_whitelist 
     [[mView wy_objWhitelist] addObject:makeWeakReference(mView_subView)];
    
    • filter class
     // add class_whitelist
     [[self.tableView wy_classWhitelist] addObject:makeWeakReference([mView_subView class])];

Hope

If you think it's useful, star to me, Free to share with ideas, issue or pull requests

License

MIT

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.