在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. codeforces 633G. Yash And Trees dfs序+线段树+bitset

    题目链接 G. Yash And Trees time limit per test 4 seconds memory limit per test 512 megabytes input stand ...

  2. The c programming language第一章节所有程序的实现

    //打印第一个程序hello, word #include<stdio.h> int main() { printf("hello, world\n"); ; } // ...

  3. 《Pointers On C》读书笔记(第一章 快速上手)

    1.C语言是一种自由格式的程序设计语言,没有规则要求我们必须如何书写语句.然而,如果我们在编写程序时能够遵守一些约定还是非常值得的,它可以使代码更加容易阅读和修改.另外,预处理命令有较为严格的规则. ...

  4. 在CI框架下执行存储的方法

    我直接把代码摆在这里分享哈 <?php /** * * Created by JetBrains PhpStorm. * User: lsl * Date: 14-1-8 * Time: 下午2 ...

  5. Wide character in print at hcp.pl line 21.

    jrhmpt01:/root# cat -n hcp.pl 1 use LWP::UserAgent; 2 use Encode; 3 $ua = LWP::UserAgent->new; 4 ...

  6. BZOJ 4259 残缺的字符串(FFT)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4259 [题目大意] 给出两个包含*和小写字母的字符串,*为适配符,可以和任何字符匹配, ...

  7. python import 自己的包

    在写python时,有时候写的一个python文件可能需要被其他python文件所用,那么可以用导入包 import 的 方式: 1.自己写的包放到哪里? >>> import sy ...

  8. hbase0.96 put流程 源码分析

    无意间多瞄了一眼hbase0.98的代码,想复习下put流程.发现htable里面已经找不到processBatchOfPuts()奇怪了.看了半天原来变化还真大事实上0.96就没这个了,于是又搞了个 ...

  9. PHP中递归函数的一个常见逻辑问题

    首先.我们得知道递归函数是什么东西.通俗来讲也就是自己调用自己本身的函数. 如今须要设计一段代码.解决1到10叠加的问题. 代码A: <?php //递归函数 $num=10; function ...

  10. HDU1046:Gridland

    Problem Description For years, computer scientists have been trying to find efficient solutions to d ...