//
// ZSDTJNoDataView.h
// ZSDTJNoDataView
//
// Created by Mac on 14-12-28.
// Copyright (c) 2014年 ZSD. All rights reserved.
// //当发起网络请求的时候没有数据的时候界面显示指定的背景图
#import <UIKit/UIKit.h>
typedef void(^ZSDNoDataViewCompleteHandler) (NSInteger buttonIndex) ;
typedef NS_ENUM(NSInteger, ZSDNoDataViewType)
{
ZSDNoDataViewTypeInvestMent=, //投资理财
ZSDNoDataViewTypeRecord,//交易记录
ZSDNoDataViewTypeMyInvest,//我的投资
ZSDNoDataViewTypeNews,//消息中心
ZSDNoDataViewTypePlan //回款计划 }; @class ZSDTJNoDataView;
@protocol ZSDTJNoDataViewDelegate <NSObject>
-(void)noDataView:(ZSDTJNoDataView *)noDataView andButtonClick:(NSInteger)selectBtnIndex;
@end
@interface ZSDTJNoDataView : UIView
{
ZSDNoDataViewCompleteHandler completeHandler;
}
@property(nonatomic,weak)id<ZSDTJNoDataViewDelegate>delegate; +(void)showInBaseView:(UIView *)baseView andNoDataViewType:(ZSDNoDataViewType)noDataViewType andCompeleteHandler:(ZSDNoDataViewCompleteHandler) handler; -(void)showInBaseView:(UIView *)baseView andNoDataViewDelegate:(id)delegate andNoDataViewType:(ZSDNoDataViewType)noDataViewType; -(void)showInBaseView:(UIView *)baseView andNoDataViewType:(ZSDNoDataViewType)noDataViewType andCompeleteHandler:(ZSDNoDataViewCompleteHandler) handler ; @end
//
// ZSDTJNoDataView.m
// ZSDTJNoDataView
//
// Created by Mac on 14-12-28.
// Copyright (c) 2014年 ZSD. All rights reserved.
// #import "ZSDTJNoDataView.h"
//红色按钮正常状态
#define kRedButtonNormalColor [UIColor colorWithRed:0.84 green:0.23 blue:0.29 alpha:1]
#define kImageSize CGSizeMake(55.0f,55.0f)
@implementation ZSDTJNoDataView
{
UIView *contentView;//存放所有控件的view;
UILabel *textLabel;//文本label
UIImageView *photoImageView;//显示图片
UIButton *redButton;//按钮 }
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void)setUpNoDataView:(ZSDNoDataViewType)noDataViewType
{
//创建一个contentview对象
contentView=[[UIView alloc]init];
contentView.translatesAutoresizingMaskIntoConstraints=NO;
[self addSubview:contentView]; //为contentview添加水平约束
NSArray *contentView_H=[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[contentView]|" options: metrics:nil views:NSDictionaryOfVariableBindings(contentView)];
[self addConstraints:contentView_H]; //创建一个photoImage对象
photoImageView=[[UIImageView alloc]init];
photoImageView.translatesAutoresizingMaskIntoConstraints=NO;
[contentView addSubview:photoImageView]; //为photoImage添加水平约束
NSDictionary *dic_photoImageView=@{@"imageWith":@(kImageSize.width)};
NSArray *photoImageView_H=[NSLayoutConstraint constraintsWithVisualFormat:@"H:[photoImageView(imageWith)]" options: metrics:dic_photoImageView views:NSDictionaryOfVariableBindings(photoImageView)];
//为photoImage添加水平居中约束
NSLayoutConstraint *photoImageView_CX=[NSLayoutConstraint constraintWithItem:photoImageView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:contentView attribute:NSLayoutAttributeCenterX multiplier: constant:];
[contentView addConstraints:photoImageView_H];
[contentView addConstraint:photoImageView_CX]; //创建一个textLabel对象
textLabel=[[UILabel alloc]init];
textLabel.translatesAutoresizingMaskIntoConstraints=NO;
textLabel.backgroundColor = [UIColor clearColor];
textLabel.font = [UIFont systemFontOfSize:17.0f];
textLabel.textAlignment = NSTextAlignmentCenter;
textLabel.textColor = [UIColor colorWithRed:/255.0f green:/255.0f blue:/255.0f alpha:1.0];
[contentView addSubview:textLabel]; //水平添加约束
NSDictionary *dic_textLabel=@{@"LeftMarginRight":@(20.0f)};
NSArray *textLabel_H=[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-LeftMarginRight-[textLabel]-LeftMarginRight-|" options: metrics:dic_textLabel views:NSDictionaryOfVariableBindings(textLabel)];
[contentView addConstraints:textLabel_H]; //创建一个redButton对象
redButton=[[UIButton alloc]initWithFrame:CGRectZero];
redButton.tag=;
redButton.translatesAutoresizingMaskIntoConstraints=NO;
[redButton setTitle:@"马上去投资" forState:UIControlStateNormal];
[redButton setBackgroundColor:kRedButtonNormalColor];
[redButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[redButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[contentView addSubview:redButton]; //为redButton添加水平约束
NSDictionary *dic_redButton=@{@"LeftorRight":@(16.0f)};
NSArray *redButton_H=[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-LeftorRight-[redButton]-LeftorRight-|" options: metrics:dic_redButton views:NSDictionaryOfVariableBindings(redButton)];
[contentView addConstraints:redButton_H]; //把所有控件放在最终的父视图中并添加约束
NSDictionary *bindDic=@{@"photoImageView":photoImageView,@"textLabel":textLabel,@"redButton":redButton};
NSDictionary *dic_constraint = @{@"margin":@(15.0f),@"margin_redButton":@(24.0f),@"imgHeight":@(kImageSize.height),@"textHeight":@(20.0f),@"redButtonHeight":@(44.0f)}; NSString *formatStr = [NSString stringWithFormat:@"V:|-[photoImageView(imgHeight)]-margin-[textLabel(textHeight)]-margin_redButton-[redButton(redButtonHeight)]-|"];
NSArray *constraint_V=[NSLayoutConstraint constraintsWithVisualFormat:formatStr options: metrics:dic_constraint views:bindDic];
[contentView addConstraints:constraint_V]; }
-(void)showInView:(UIView *)baseView andNoDataViewType:(ZSDNoDataViewType)noDataViewType
{
switch (noDataViewType)
{ case ZSDNoDataViewTypeInvestMent:
{
photoImageView.image=[UIImage imageNamed:@"invest_circle_none"];
textLabel.text=@"没有相关记录";
break;
}
case ZSDNoDataViewTypeMyInvest:
{
photoImageView.image=[UIImage imageNamed:@""];
textLabel.text=@"没有相关记录";
break;
}
case ZSDNoDataViewTypeNews:
{
photoImageView.image=[UIImage imageNamed:@"our_news_none"];
textLabel.text=@"没有相关记录";
break;
}
case ZSDNoDataViewTypePlan:
{
photoImageView.image=[UIImage imageNamed:@"reimbursement_plan_none"];
textLabel.text=@"没有正在回款的项目";
break;
}
case ZSDNoDataViewTypeRecord:
{
photoImageView.image=[UIImage imageNamed:@"Invest_record_none"];
textLabel.text=@"没有相关记录";
break;
}
default:
break;
}
//获取contentview更新约束后实际大小
CGSize contentSize=[contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
//添加垂直约束
NSDictionary *dic_contentView = @{@"height":@(contentSize.height)};
NSArray *contentView_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[contentView(height)]" options: metrics:dic_contentView views:NSDictionaryOfVariableBindings(contentView)];
NSLayoutConstraint *contentView_CY = [NSLayoutConstraint constraintWithItem:contentView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier: constant:];
[self addConstraints:contentView_V];
[self addConstraint:contentView_CY];
[baseView addSubview:self]; self.translatesAutoresizingMaskIntoConstraints = NO;
NSArray *self_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[self]|" options: metrics: views:NSDictionaryOfVariableBindings(self)];
NSArray *self_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[self]|" options: metrics: views:NSDictionaryOfVariableBindings(self)];
[baseView addConstraints:self_H];
[baseView addConstraints:self_V]; }
//代理
-(void)showInBaseView:(UIView *)baseView andNoDataViewDelegate:(id)delegate andNoDataViewType:(ZSDNoDataViewType)noDataViewType
{
[self setUpNoDataView:noDataViewType];
self.delegate=delegate;
redButton.hidden=noDataViewType==ZSDNoDataViewTypeMyInvest?NO:YES;
[self showInView:baseView andNoDataViewType:noDataViewType];
}
//block回调
-(void)showInBaseView:(UIView *)baseView andNoDataViewType:(ZSDNoDataViewType)noDataViewType andCompeleteHandler:(ZSDNoDataViewCompleteHandler)handler
{
[self setUpNoDataView:noDataViewType];
completeHandler=handler;
redButton.hidden=noDataViewType==ZSDNoDataViewTypeMyInvest?NO:YES;
[self showInView:baseView andNoDataViewType:noDataViewType]; }
//类方法block回调
+(void)showInBaseView:(UIView *)baseView andNoDataViewType:(ZSDNoDataViewType)noDataViewType andCompeleteHandler:(ZSDNoDataViewCompleteHandler)handler
{
ZSDTJNoDataView *noDataView=[[ZSDTJNoDataView alloc]init];
[noDataView setUpNoDataView:noDataViewType];
noDataView->completeHandler=handler;
noDataView->redButton.hidden=noDataViewType==ZSDNoDataViewTypeMyInvest?NO:YES;
[noDataView showInView:baseView andNoDataViewType:noDataViewType]; }
-(void)buttonAction:(UIButton *)sender
{
//使用代理
if (_delegate&&[_delegate respondsToSelector:@selector(noDataView:andButtonClick:)])
{
[_delegate noDataView:self andButtonClick:sender.tag];
}
//使用block调
if (completeHandler)
{
completeHandler(sender.tag);
}
}
@end
#import <UIKit/UIKit.h>
#import "ZSDTJNoDataView.h"
@interface ZSDViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIView *maskView; @end
//
// ZSDViewController.m
// ZSDTJNoDataView
//
// Created by Mac on 14-12-28.
// Copyright (c) 2014年 ZSD. All rights reserved.
// #import "ZSDViewController.h" @interface ZSDViewController ()<ZSDTJNoDataViewDelegate>
{
ZSDTJNoDataView *noDataView;
}
@end @implementation ZSDViewController - (void)viewDidLoad
{
[super viewDidLoad];
noDataView=[[ZSDTJNoDataView alloc]init];
[noDataView showInBaseView:_maskView andNoDataViewType:ZSDNoDataViewTypeMyInvest andCompeleteHandler:^(NSInteger buttonIndex) { NSLog(@"使用回调时候buttonIndex=%d",buttonIndex); }];
[noDataView showInBaseView:_maskView andNoDataViewDelegate:self andNoDataViewType:ZSDNoDataViewTypeMyInvest]; [ZSDTJNoDataView showInBaseView:_maskView andNoDataViewType:ZSDNoDataViewTypeMyInvest andCompeleteHandler:^(NSInteger buttonIndex) { NSLog(@"使用类方法回调时候buttonIndex=%d",buttonIndex);
}];
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
} #pragma mark -ZSDTJNoDataView Delegate
-(void)noDataView:(ZSDTJNoDataView *)noDataView andButtonClick:(NSInteger)selectBtnIndex
{
NSLog(@"使用代理时候selectBtnIndex=%d",selectBtnIndex);
}
@end

自定义uiview 当没有数据的时候 显示自定义的uiview界面的更多相关文章

  1. 双击CAD对象(具有扩展数据),显示自定义对话框实现方法

    转自:Cad人生 链接:http://www.cnblogs.com/cadlife/p/3463337.html 题目:双击CAD对象,显示自定义对话框实现方法 内容粘贴如下: 主要是绑定两个事件: ...

  2. XE7 & FMX 那些年我们一起上过的控件:ListView 之 (3) 加载数据时如何显示自定义样式

    本文介绍一下ListView下如何加载数据.及使用进度条反馈当前进度给用户. 注意: 原创作品,请尊重作者劳动成果,转载请注明出处!!!原文永久固定地址:http://www.cnblogs.com/ ...

  3. 判断数据库内容,在页面显示自定义数据case when

    判断数据库内容,在页面显示自定义数据 case when...then ...else...end 比如:数据库内容是这样: 通过sql语句判断,数据库的name字段,内容是月桂的,显示嫦娥,其他的显 ...

  4. DedeCMS中实现在顶层banner中显示自定义登录信息

    一.需求描述 dedeCMS自带的模板中有互动中心模块,如下图所示: 由于会员登陆对我来说不是网站的重要模块且默认DedeCMS的会员中心模块的初始化很慢,常会显示“正在载入中,请稍候...”, 所以 ...

  5. Highcharts属性与Y轴数据值刻度显示Y轴最小最大值

    Highcharts 官网:https://www.hcharts.cn/demo/highcharts Highcharts API文档:https://api.hcharts.cn/highcha ...

  6. iOS:自定义导航栏,随着tableView滚动显示和隐藏

    自定义导航栏,随着tableView滚动显示和隐藏 一.介绍 自定义导航栏是APP中很常用的一个功能,通过自定义可以灵活的实现动画隐藏和显示效果.虽然处理系统的导航栏也可以实现,但是这个是有弊端的,因 ...

  7. HighCharts 图表插件 自定义绑定 时间轴数据

    HighCharts 图表插件 自定义绑定 时间轴数据,解决时间轴自动显示数据与实际绑定数据时间不对应问题! 可能要用到的源码片段:http://code.662p.com/list/14_1.htm ...

  8. 利用动态图层实现数据的实时显示(arcEngine IDynamiclayer)

    marine 原文利用动态图层实现数据的实时显示(arcEngine IDynamiclayer) 说明:最近一个项目用到这方面知识,文章主要来至网络,后期会加入自己的开发心得.(以下的代码实例中,地 ...

  9. 9) drf JWT 认证 签发与校验token 多方式登陆 自定义认证规则反爬 admin密文显示

    一 .认证方法比较 1.认证规则图 django 前后端不分离 csrf认证 drf 前后端分离 禁用csrf 2. 认证规则演变图 数据库session认证:低效 缓存认证:高效 jwt认证:高效 ...

随机推荐

  1. PC端 $_SERVER 说明

    $_SERVER['PHP_SELF'] #当前正在执行脚本的文件名,与 document root相关. $_SERVER['argv'] #传递给该脚本的参数. $_SERVER['argc'] ...

  2. 简易的JQuery设置Cookie

    使用之前先引用这两个文件: 然后基本的功能代码如下: <div> <input id="txtDelValues" type="text" / ...

  3. 第三次作业随笔(new)包含了补作业

    第三次作业的题目:http://www.cnblogs.com/fzuoop/p/5187275.html 第一次看到题目的时候觉得应该是挺简单的,只要把输入的那一串东西挨个判断,用数列的方法,如果碰 ...

  4. HDU 3920Clear All of Them I(状压DP)

    HDU 3920   Clear All of Them I 题目是说有2n个敌人,现在可以发n枚炮弹,每枚炮弹可以(可以且仅可以)打两个敌人,每一枚炮弹的花费等于它所行进的距离,现在要消灭所有的敌人 ...

  5. 关于mysql存储过程的definer的问题

    由于对mysql了解不够透彻,导致对definer问题查了好久才解决问题 记录自己的一些理解! 问题描述: 在数据库写,为一个表写了一个触发器,此触发器调用一个存储过程:由公司写的一个c程序自动往该表 ...

  6. Java中返回参数值的几种状态

    Java 中无参无返回值方法的使用 第一步,定义方法 例如:下面代码定义了一个方法名为 show ,没有参数,且没有返回值的方法,执行的操作为输出 " welcome to imooc. & ...

  7. 转载 使用WiX Toolset创建.NET程序发布Bootstrapper(安装策略管理)(一&二)——初识WiX

    转载fromVan Pan 的专栏   http://blog.csdn.net/rryqsh/article/details/8274832 http://blog.csdn.net/rryqsh/ ...

  8. Oracle 数据库链接

    SQL> CREATE DATABASE LINK   mydblink 2    CONNECT TO   test   IDENTIFIED BY   test123 3    USING  ...

  9. DeleteDC() 与 ReleaseDC() 的区别 [转]

    DeleteDC 该函数删除指定的设备上下文环境(DC). 原型: BOOL DeleteDC(HDC hdc): 参数: hdc:设备上下文环境的句柄. 返回值: 成功,返回非零值:失败,返回零.调 ...

  10. ASP.NET服务器控件在IE10浏览器(非兼容模式)下报脚本错误的可能解决办法

    关于IE10出现LinkButton点击无效的情况:        一般高配置的系统如Win7旗舰版SP1系统不会出现这种情况,针对家庭普通版和专业版的用户通过测试都有这种情况,对于开发人员要解决不同 ...