在tableview没有数据的时候,我们经常需要在tableview的正中间插入一张图片,来提示用户暂无数据

/**
* 添加一个view,提示暂无数据
*/
- (void)addPromptView
{
UIView* promptView = [[UIView alloc] initWithFrame:CGRectMake(, , [UIScreen mainScreen].bounds.size.width, )];
UIImageView* promptImageView = [[UIImageView alloc] init];
CGFloat promptImageViewW = ;
CGFloat promptImageViewX = (promptView.frame.size.width - promptImageViewW) / ;
CGFloat promptImageViewY = ;
CGFloat promptImageViewH = ;
CGRect promptF = CGRectMake(promptImageViewX, promptImageViewY, promptImageViewW, promptImageViewH);
promptImageView.frame = promptF;
promptImageView.image = [UIImage imageNamed:@"暂无数据.png"];
promptImageView.contentMode = UIViewContentModeScaleAspectFit;
promptView.center = self.view.center;
[promptView addSubview:promptImageView];
self.promptView = promptView;
self.promptView.hidden = YES;
[self.tableView addSubview:self.promptView];

//添加约束,使promptView保持在tableview的正中间
[promptView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.tableView addConstraint:[NSLayoutConstraint constraintWithItem:promptView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.tableView attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]];
[self.tableView addConstraint:[NSLayoutConstraint constraintWithItem:promptView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.tableView attribute:NSLayoutAttributeCenterY multiplier:1.0f constant:0.0f]];
[self.tableView addConstraint:[NSLayoutConstraint constraintWithItem:promptView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0f constant:[UIScreen mainScreen].bounds.size.width]];
[self.tableView addConstraint:[NSLayoutConstraint constraintWithItem:promptView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0f constant:150.0f]]; }

使用约束给tableview添加暂无数据的提示的更多相关文章

  1. Swift - 给表格TableView添加页眉和页脚

    UITableView具有var tableHeaderView:UIView?属性和var tableFooterView:UIView?属性,可以通过给其赋值来创建列表TableView的页眉和页 ...

  2. Repeater 控件 当数据源没有数据的时候显示 暂无数据 的两种方式

    第一种:现在前台给Repeater控件外面的div加一个runat=”server”  然后在cs后台判断数据源是否为空, 是的话就修改这个前台div的InnerText或者是InnerHtml 即可 ...

  3. easyUI datagrid表格添加“暂无记录”显示

    扩展grid的onAfterRender事件 var myview = $.extend({}, $.fn.datagrid.defaults.view, {     onAfterRender: f ...

  4. element table 先显示暂无数据 之后再加载数据 问题

    项目中的表格请求数据时,进去页面,先出现 ''暂无数据'' 字样闪现一下之后在进行加载数据,用户体验十分不好 解决办法: <template> <el-table :data=&qu ...

  5. 使用Vue封装暂无数据占位图组件

    1. 前言 在日常开发中,页面上肯定有展示数据的需求,但是当某些时候该展示数据的地方此时数据为空时,就会留下一片空白,对用户体验不是很好,那么接下来我们就封装一个空数据时的占位展示图,告诉用户此时用户 ...

  6. element el-tree、el-table组件加载数据前闪现 暂无数据 清除

    相信很多人在使用element  el-tree.el-table组件加载数据前会显示一个" 暂无数据 ",体验很不友好,有没有办法处理不显示呢?答案是:有的.废话不多说直接上代码 ...

  7. iOS开发小技巧--tableView中实现无数据无分割线,有数据才有分割线

    通过通讯录练习GET的技能

  8. ios见习之-UISearchbar+tableview实现自动搜索自带提示

    当做搜索时常常希望能在输入的时候出现搜索关键字,如下效果

  9. 添加xml文件编辑语法提示

    找到Struts的lib目录 找到struts2-core-文件并解压开 这个struts.dtd文件才是我们需要添加的文件 双击XML Catalog 点击ADD Key中复制粘贴D:\web\st ...

随机推荐

  1. MySQL学习系列一---命令行连接mysql和执行sql文件

    1.命令行连接mysql #mysql -h(主机) -u(用户名) -p (数据库名) mysql -hlocalhost -uroot -p testdb Enter password: **** ...

  2. Mysql 笔记:

    1:可以查看information_schema.index_statistics 来查看索引的使用信息.还可以使用pt-index-usage 这个工具来分析日志再结合explain 来分析使用的索 ...

  3. 关于crontab笔记

    如下所示,一般crontab文件里面的定时任务格式如下所示: 59 23 * * * /home/oracle/scripts/alert_log_archive.sh >/dev/null 2 ...

  4. C++STL之string (转)

    在学习c++STL中的string,在这里做个笔记,以供自己以后翻阅和初学者参考. 1:string对象的定义和初始化以及读写 string s1;      默认构造函数,s1为空串 string ...

  5. Robolectric 探索之路

    layout: post title: Roboletric探索之路,从抗拒到依赖 description: Roboletric Android Unit Testing category: blo ...

  6. POJ 1459 Power Network(网络流 最大流 多起点,多汇点)

    Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 22987   Accepted: 12039 D ...

  7. iOS 10中如何搭建一个语音转文字框架

    在2016WWDC大会上,Apple公司介绍了一个很好的语音识别的API,那就是Speech framework.事实上,这个Speech Kit就是Siri用来做语音识别的框架.如今已经有一些可用的 ...

  8. poj1084Square Destroyer(LDX解重复覆盖)

    题目请戳这里 题目大意:给一个n*n的用单位长度的木棍拼起来的网格图,给每个木棍按图示编号,编号范围1~2*n*(n+1).现在已知图中已经去掉了k个木棍,求还要至少去掉几根木棍能使网格图中不存在正方 ...

  9. Android 开发笔记 “Sqlite Cursor 使用”

    使用过 SQLite 数据库的童鞋对 Cursor 应该不陌生,如果你是搞.net 开发你大可以把Cursor理解成 Ado.net 中的数据集合相当于dataReader.今天特地将它单独拿出来谈, ...

  10. Webx pull service

    1.概述 pull service的功能是将对象置入模板中.被pull service放到模板中的对象,不需要应用程序的干预即可直接使用.如果模板没有用到某个对象,则不会产生创建该对象的开销.看起来, ...