自定义uiview 当没有数据的时候 显示自定义的uiview界面

//
//  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=0, //投资理财
  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:0 metrics:nil views:NSDictionaryOfVariableBindings(contentView)];
    [self addConstraints:contentView_H];

    //创建一个photoImage对象
    photoImageView=[[UIImageView alloc]init];
    photoImageView.translatesAutoresizingMaskIntoConstraints=NO;
    [contentView addSubview:photoImageView];

    //为photoImage添加水平约束
    NSDictionary *[email protected]{@"imageWith":@(kImageSize.width)};
    NSArray *photoImageView_H=[NSLayoutConstraint constraintsWithVisualFormat:@"H:[photoImageView(imageWith)]" options:0 metrics:dic_photoImageView views:NSDictionaryOfVariableBindings(photoImageView)];
    //为photoImage添加水平居中约束
    NSLayoutConstraint *photoImageView_CX=[NSLayoutConstraint constraintWithItem:photoImageView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:contentView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
    [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:191/255.0f green:191/255.0f blue:191/255.0f alpha:1.0];
    [contentView addSubview:textLabel];

    //水平添加约束
    NSDictionary *[email protected]{@"LeftMarginRight":@(20.0f)};
    NSArray *textLabel_H=[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-LeftMarginRight-[textLabel]-LeftMarginRight-|" options:0 metrics:dic_textLabel views:NSDictionaryOfVariableBindings(textLabel)];
    [contentView addConstraints:textLabel_H];

    //创建一个redButton对象
    redButton=[[UIButton alloc]initWithFrame:CGRectZero];
    redButton.tag=0;
    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 *[email protected]{@"LeftorRight":@(16.0f)};
    NSArray *redButton_H=[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-LeftorRight-[redButton]-LeftorRight-|" options:0 metrics:dic_redButton views:NSDictionaryOfVariableBindings(redButton)];
    [contentView addConstraints:redButton_H];

    //把所有控件放在最终的父视图中并添加约束
    NSDictionary *[email protected]{@"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:0 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:@"2"];
            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:0 metrics:dic_contentView views:NSDictionaryOfVariableBindings(contentView)];
    NSLayoutConstraint *contentView_CY = [NSLayoutConstraint constraintWithItem:contentView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1 constant:0];
    [self addConstraints:contentView_V];
    [self addConstraint:contentView_CY];
    [baseView addSubview:self];

    self.translatesAutoresizingMaskIntoConstraints = NO;
    NSArray *self_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[self]|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(self)];
    NSArray *self_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[self]|" options:0 metrics:0 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

时间: 2024-08-01 23:36:07

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

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

转自:Cad人生 链接:http://www.cnblogs.com/cadlife/p/3463337.html 题目:双击CAD对象,显示自定义对话框实现方法 内容粘贴如下: 主要是绑定两个事件:一个是 Application.DocumentManager.DocumentLockModeChanged ----- 该事件为文档锁定事件,一直在被监测中 一个是 Application.BeginDoubleClick ----- 该事件为应用程序的双击事件 1 class TlsAppli

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

本文介绍一下ListView下如何加载数据.及使用进度条反馈当前进度给用户. 注意: 原创作品,请尊重作者劳动成果,转载请注明出处!!!原文永久固定地址:http://www.cnblogs.com/weii/p/4190719.html 我们先来看看效果图: FMX异常强大,我们可以发挥想像,自定义进度样式,以下为本文参考代码: procedure TForm1.Button3Click(Sender: TObject); var pe: TPie; //扇形作进度 rc: TRoundRec

UITableView自定义UITableViewCell中传入数据不显示

通常我们在自定义一个UITableViewCell时,从网络上获取数据,传入到自定义tableviewcell类中,进行加载,运行程序之后,发现仍然没有数据显示: 这里我们以简单的数据源形式来做一次实验,如图所示: 这里_dataSource为NSArray的对象,CustomTableViewCell为自定义cell类,当前为viewcontroller 中的代码: 如下图,为自定义cell中的代码部分: CustomTableViewCell.h头文件部分: CustomTableViewC

MapKit之大头针全面解析(使用系统大头针、自定义大头针callout视图、使用图片显示大头针)

首先了解一些相关知识点: 添加大头针到地图 在iOS开发中经常会标记某个位置,需要使用地图标注,也就是大家俗称的"大头针".大头针(Annotations)提供了一种方式来突出地图中具体的位置并可以提供相关的信息.我们能够使用大头针标记具体的地址,兴趣点和其他类型的目的地.当显示在地图上的时候,大头针可以使用图片作为标识,也能够点击大头针弹出小弹框提供相应的链接和具体内容.Figure6-1显示了系统标准的大头针样式标记具体的位置,并提供了小弹框显示额外的信息,使用箭头提示用户点击获取

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

Highcharts 官网:https://www.hcharts.cn/demo/highcharts Highcharts API文档:https://api.hcharts.cn/highcharts#yAxis.tickmarkPlacement Highcharts属性与Y轴数据值刻度显示Y轴最小最大值 Highcharts.setOptions({global:{useUTC : false}}); $(function(){ //声明报表对象 var chart = new Hig

利用动态图层实现数据的实时显示

转自原文 利用动态图层实现数据的实时显示 (ArcEngine IDynamiclayer) 说明:最近一个项目用到这方面知识,文章主要来至网络,后期会加入自己的开发心得.(以下的代码实例中,地图看样子是采用ADF开发)    1.1 前言 不刷新地图而能让数据实时显示,这在ArcGIS中已经不在是一个困扰我们的难题,在ArcGIS Engine的开发过程中,每一次更新数据后都需要刷新才能,更改大量数据并不断的刷新,让用户在静静的等待,这不是很痛苦吗?为此ArcGIS提供了一个动态图层,专门用于

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

HighCharts 图表插件 自定义绑定 时间轴数据,解决时间轴自动显示数据与实际绑定数据时间不对应问题! 可能要用到的源码片段:http://code.662p.com/list/14_1.html     学习示例如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quo

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

一 .认证方法比较 1.认证规则图 django 前后端不分离 csrf认证 drf 前后端分离 禁用csrf 2. 认证规则演变图 数据库session认证:低效 缓存认证:高效 jwt认证:高效 3. 认证比较 """ 1)session存储token,需要数据库参与,耗服务器资源.低效 2)缓存存token,需要缓存参与,高效,不易集群 3)客户端存token,服务器存签发与交易token的算法,高效,易集群 """ 缓存认证: 不易并发

QT: QByteArray储存二进制数据(包括结构体,自定义QT对象)

因为利用QByteArray可以很方便的利用其API对内存数据进行访问和修改, 构建数据库blob字段时必不可少; 那如何向blob内写入自定义的结构体和类 1. 利用memcpy拷贝内存数据 //自定义person结构体 Cpp代码   typedef struct { int age; char name[20]; }Person; //向QByteArray写入多个结构体 void writeStruct() { QByteArray ba; ba.resize(2*sizeof(Pers