第三方库DZNEmptyDataSet使用示例
来源:互联网 发布:豪迪群发软件 编辑:程序博客网 时间:2024/06/18 16:43
本文介绍怎么使用第三方库DZNEmptyDataSet,以后项目开发时可能会用到。
程序执行后的界面为:
下面上干货。
1,向工程中加入第三方库。加完后的工程应该是这样的:
2.在故事板中增加一个tableView控件,设置好四个方向的约束属性。
3.设置outlet绑定、协议委托,具体.m和.h代码为:
//// ViewController.h// TestDZNEmptyDataSet//#import <UIKit/UIKit.h>/* STEP1:引入第三方类库 */#import "UIScrollView+EmptyDataSet.h"/* STEP2:引入代理协议 */@interface ViewController : UIViewController <DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>/* STEP3:拖动一个TableView控件并进行关联 */@property (strong, nonatomic) IBOutlet UITableView *theTableView;@end
//// ViewController.m// TestDZNEmptyDataSet#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { /* STEP4:设置代理 */ self.theTableView.emptyDataSetSource = self; self.theTableView.emptyDataSetDelegate = self; /* STEP5:去掉TableView中的默认横线 */ self.theTableView.tableFooterView = [UIView new]; [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}/* STEP6: Return the content you want to show on the empty state, and take advantage of NSAttributedString features to customise the text appearance.*/#pragma mark ---- Data Source Implementation ----/* The image for the empty state */- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{ NSLog(@"imageForEmptyDataSet:empty_placeholder"); return [UIImage imageNamed:@"empty_placeholder"];}/* The image view animation */- (CAAnimation *)imageAnimationForEmptyDataSet:(UIScrollView *)scrollView{ NSLog(@"imageAnimationForEmptyDataSet"); CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath: @"transform"]; animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity]; animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2, 0.0, 0.0, 1.0)]; animation.duration = 0.25; animation.cumulative = YES; animation.repeatCount = MAXFLOAT; return animation;}#if 0/* The attributed string for the title of the empty state */- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{ NSLog(@"titleForEmptyDataSet:Please Allow Photo Access"); NSString *text = @"Please Allow Photo Access"; NSDictionary *attributes = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:18.0f], NSForegroundColorAttributeName: [UIColor darkGrayColor]}; return [[NSAttributedString alloc] initWithString:text attributes:attributes];}#endif/* The attributed string for the description of the empty state */- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView{ NSLog(@"descriptionForEmptyDataSet:您还没有上传照片"); NSString *text = @"您还没有上传照片"; NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new]; paragraph.lineBreakMode = NSLineBreakByWordWrapping; paragraph.alignment = NSTextAlignmentCenter; NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0f], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph}; return [[NSAttributedString alloc] initWithString:text attributes:attributes];}/* The attributed string to be used for the specified button state */- (NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state{ NSLog(@"buttonTitleForEmptyDataSet:点击上传照片"); NSDictionary *attributes = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:17.0f]}; return [[NSAttributedString alloc] initWithString:@"点击上传照片" attributes:attributes];}#if 0/* or the image to be used for the specified button state. 注:图片优先级高于文字. */- (UIImage *)buttonImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state{ NSLog(@"buttonImageForEmptyDataSet:button_image"); return [UIImage imageNamed:@"button_image"];}#endif/* The background color for the empty state */- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView{ NSLog(@"backgroundColorForEmptyDataSet"); return [UIColor brownColor]; // redColor whiteColor}#if 0/* 显示等待状态: If you need a more complex layout, you can return a custom view instead: */- (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView{ NSLog(@"customViewForEmptyDataSet"); UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; [activityView startAnimating]; return activityView;}#endif/* Additionally, you can also adjust the vertical alignment of the content view (ie: useful when there is tableHeaderView visible): */- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView{ NSLog(@"verticalOffsetForEmptyDataSet"); return -self.theTableView.tableHeaderView.frame.size.height/2.0f;}/* Finally, you can separate components from each other (default separation is 11 pts): */- (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{ NSLog(@"spaceHeightForEmptyDataSet"); return 20.0f;}/* STEP7: Return the behaviours you would expect from the empty states, and receive the user events.*/#pragma mark ---- Delegate Implementation ----/* Asks to know if the empty state should be rendered and displayed (Default is YES) : */- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView{ NSLog(@"emptyDataSetShouldDisplay"); return YES;}/* Asks for interaction permission (Default is YES) : */- (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView{ NSLog(@"emptyDataSetShouldAllowTouch"); return YES;}/* Asks for scrolling permission (Default is NO) : */- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{ NSLog(@"emptyDataSetShouldAllowScroll"); return NO;}/* Asks for image view animation permission (Default is NO) : */- (BOOL) emptyDataSetShouldAllowImageViewAnimate:(UIScrollView *)scrollView{ NSLog(@"emptyDataSetShouldAllowImageViewAnimate"); return YES;}/* Notifies when the dataset view was tapped: */- (void)emptyDataSetDidTapView:(UIScrollView *)scrollView{ NSLog(@"emptyDataSetDidTapView"); // Do something}/* Notifies when the data set call to action button was tapped: */- (void)emptyDataSetDidTapButton:(UIScrollView *)scrollView{ NSLog(@"emptyDataSetDidTapButton"); // Do something}@end
4.代码中使用到了图片文件,因此增加相应的image文件:
5.代码里还有一些是if 0注掉的代码,这些代码在实际使用中可以根据需要放开。
好了,到这里就完成了,很简单吧。
2 0
- 第三方库DZNEmptyDataSet使用示例
- [CMake] 第三方库使用示例
- DZNEmptyDataSet(一个好用的空白页展示第三方)
- Geohash第三方库示例
- 第三方登录示例
- liunx使用第三方库
- UE4使用第三方库
- 第三方库的使用
- Qt使用第三方库
- Qt使用第三方库
- UE4使用第三方库
- qt 使用第三方库
- 第三方库的使用
- C++第三方库使用
- python第三方库使用
- DZNEmptyDataSet
- 第三方QQ登录示例
- QQ第三方登录示例
- CCF-201509-1
- OSChina App代码分析一
- java#0 基本概念
- 在eclipse中运行工程时 出现<ConnectionProperties> <PropertyCategory name="Connection/Authentication">的解决方法
- Drools介绍
- 第三方库DZNEmptyDataSet使用示例
- java web单点登录异常情况处理
- 基础--模电学习
- RegSaveKey备份注册表中遇到的权限问题
- 【codevs2452】【SCOI2005】【BZOJ1088】扫雷Mine
- 电子邮件发送-python
- poj1088滑雪【记忆化搜索 初级题】
- 数据结构--Chapter7(内排序)
- activity生命周期