Latest 1.0.3
Homepage https://github.com/WymanLyu/WYNullView
License MIT
Platforms ios 5.0
Authors

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

Latest podspec

{
    "name": "WYNullView",
    "version": "1.0.3",
    "summary": "An easy way to use when view' content is empty",
    "description": "This lib has been designed in a way where you won't need to extend UIView class. You will be able to fully customize the content and appearance of the empty states for your application",
    "homepage": "https://github.com/WymanLyu/WYNullView",
    "license": "MIT",
    "authors": {
        "wyman": "[email protected]"
    },
    "platforms": {
        "ios": "5.0"
    },
    "source": {
        "git": "https://github.com/WymanLyu/WYNullView.git",
        "tag": "1.0.3"
    },
    "source_files": "WYNullView/WYNullView.h",
    "public_header_files": "WYNullView/WYNullView.h",
    "resources": "WYNullView/WYNullView.bundle",
    "subspecs": [
        {
            "name": "Tool",
            "source_files": "WYNullView/Tool/*.{h,m}",
            "public_header_files": "WYNullView/Tool/*.h"
        },
        {
            "name": "View",
            "source_files": "WYNullView/View/*.{h,m}",
            "public_header_files": "WYNullView/View/*.h"
        },
        {
            "name": "Category",
            "dependencies": {
                "WYNullView/View": [],
                "WYNullView/Tool": []
            },
            "source_files": "WYNullView/Category/*.{h,m}",
            "public_header_files": "WYNullView/Category/*.h"
        }
    ]
}

Pin It on Pinterest

Share This