python tableview没有数据时的占位处理_封装一个简单无数据占位图( XXNoDataView)...

8d07faba3a2a5cd6db830faeb43c62af.png

前言:撸一个自己封装使用的无数据占位图,比较简单,当然适合自己的才是最重要的。

废话不多说,一言不合就扔代码。

命名XXNoDataView,继承UIView;先来看.h文件:

import

@interface XXNoDataView : UIView

-(void)reloadWithPicName:(NSString *)picName AndTitle:(NSString *)titleStr;

@end

再来看看.m文件:

import "XXNoDataView.h"

@interface XXNoDataView ()

{

UIImageView *contentImage;

UILabel *titleLabel;

}

@end

@implementation XXNoDataView

-(instancetype)initWithFrame:(CGRect)frame

{

self = [super initWithFrame:frame];

if (self) {

self.backgroundColor = [UIColor whiteColor];

[self createView];

}

return self;

}

-- (void)createView{

contentImage = [[UIImageView alloc]init];

contentImage.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2-60);

contentImage.bounds = CGRectMake(0, 0, 68, 68);

[self addSubview:contentImage];

titleLabel = [[UILabel alloc]init];

titleLabel.center = CGPointMake(self.frame.size.width/2, self.frame.size.height/2+10);

titleLabel.font = FONT_OF_SIZE(14);

titleLabel.textColor = RGBACOLOR(188, 188, 188, 1);

[self addSubview:titleLabel];

}

-(void)reloadWithPicName:(NSString *)picName AndTitle:(NSString *)titleStr{

contentImage.image = [UIImage imageNamed:picName];

titleLabel.text = titleStr;

CGSize size = [titleLabel sizeThatFits:CGSizeMake(0, 40)];

titleLabel.bounds = CGRectMake(0, 0, size.width, size.height);

}

如何使用:

网络请求数据的时候,判断dateArr.count是否为零;是的话就在当前view加载NoDataView,否的话加载你请求的数据喽。

举个栗子:

if (!(dateArr.count>0)) {

noDataView = [[XXNoDataView alloc]initWithFrame:myHTableView.frame];

[noDataView reloadWithPicName:@"ic_empty" AndTitle:@"暂时没有任务"];

[weakself.view addSubview:noDataView];

}

1b1b6a0610f4e970b468779d7046e0cc.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值