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

效果图如下:
代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import UIKit
 
class ViewController: UIViewController,UITableViewDelegate,
    UITableViewDataSource,UIGestureRecognizerDelegate {
     
    var tableView:UITableView?
     
    var ctrlnames:[String] = ["UILabel 标签","UIButton 按钮","UIDatePiker 日期选择器"]
     
    override func viewDidLoad() {
        super.viewDidLoad()
         
        //创建表视图
        self.tableView = UITableView(frame: UIScreen.mainScreen().applicationFrame,
            style:UITableViewStyle.Plain)
        self.tableView!.delegate = self
        self.tableView!.dataSource = self
        //创建一个重用的单元格
        self.tableView!.registerClass(UITableViewCell.self, forCellReuseIdentifier: "SwiftCell")
        self.view.addSubview(self.tableView!)
         
        //给TableView添加表头页眉
        var headerView:UIView = UIView(frame: CGRectMake(0,0,tableView!.frame.size.width,60))
        var headerlabel:UILabel = UILabel(frame: headerView.bounds)
        headerlabel.textColor = UIColor.whiteColor()
        headerlabel.backgroundColor = UIColor.clearColor()
        headerlabel.font = UIFont.systemFontOfSize(16)
        headerlabel.text = "TableView 页眉"
        headerView.addSubview(headerlabel)
        headerView.backgroundColor = UIColor.blackColor()
        tableView?.tableHeaderView = headerView
         
        //给TableView添加表头页尾
        var footerView:UIView = UIView(frame: CGRectMake(0,0,tableView!.frame.size.width,60))
        var footerlabel:UILabel = UILabel(frame: footerView.bounds)
        footerlabel.textColor = UIColor.whiteColor()
        footerlabel.backgroundColor = UIColor.clearColor()
        footerlabel.font = UIFont.systemFontOfSize(16)
        footerlabel.text = "TableView 页眉"
        footerView.addSubview(footerlabel)
        footerView.backgroundColor = UIColor.blackColor()
        tableView?.tableFooterView = footerView
    }
     
    //在本例中,只有一个分区
    func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
        return 1;
    }
     
    //返回表格行数(也就是返回控件数)
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.ctrlnames.count
    }
     
    //创建各单元显示内容(创建参数indexPath指定的单元)
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
        -> UITableViewCell
    {
        //为了提供表格显示性能,已创建完成的单元需重复使用
        let identify:String = "SwiftCell"
        //同一形式的单元格重复使用,在声明时已注册
        let cell = tableView.dequeueReusableCellWithIdentifier(identify, forIndexPath: indexPath)
            as UITableViewCell
        cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
        cell.textLabel?.text = self.ctrlnames[indexPath.row]
        return cell
    }
}

Swift - 给表格TableView添加页眉和页脚的更多相关文章

  1. iOS开发——UI_swift篇&TableView实现页眉和页脚

    TableView实现页眉和页脚   在UItableView中header和footer是很常见的,而且他能让你实现很复杂的功能,我们见过最多的就是下拉刷新和上啦加载更多,当然你还可以在上面添加一个 ...

  2. openxml(二) 添加页眉,页脚

    openxml 中 word 文档的结构是如下图: 其中,页眉是 header,属于headerpart 部件,页脚是footer,属于footerpart 部件,图上还有其他的东西,之后会一一介绍. ...

  3. C# 操作Word 文档——添加Word页眉、页脚和页码

    在Word文档中,我们可以通过添加页眉.页脚的方式来丰富文档内容.添加页眉.页脚时,可以添加时间.日期.文档标题,文档引用信息.页码.内容解释.图片/LOGO等多种图文信息.同时也可根据需要调整文字或 ...

  4. C# 添加Word页眉、页脚和页码

    在Word文档中,我们可以通过添加页眉.页脚的方式来丰富文档内容.添加页眉.页脚时,可以添加时间.日期.文档标题,文档引用信息.页码.内容解释.图片/LOGO等多种图文信息.同时也可根据需要调整文字或 ...

  5. C# 给现有PDF文档添加页眉、页脚

    概述 页眉页脚是一篇完整.精致的文档的重要组成部分.在页眉页脚处,可以呈现的内容很多,如公司名称.页码.工作表名.日期.图片,如LOGO.标记等.在之前的文章中介绍了如何通过新建一页空白PDF页来添加 ...

  6. CAD在网页中打印的图纸里面添加页眉及页脚

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...

  7. NCreport报表控件教程:设计页眉和页脚

    一.设计页眉 一般来说页眉部分一般是用于包含标题的内容, 首先我们会添加列标签到页眉部分,标签都是简单的文本,标签项一般是用于在报表上显示一些描述信息,标签都是静态项,所以它们的值不会有变化. 添加标 ...

  8. iText5报表_页眉与页脚

    1.概述       iText5中并没有之前版本HeaderFooter对象设置页眉和页脚,可以利用PdfPageEventHelper来完成页眉页脚的设置工作.PdfPageEventHelper ...

  9. word页眉与页脚详解

    1.如何隔离封面等不需要插入页码的页面: 首先插入分节符下一页(一定是分节符),再在下一页(即要开始插入页码的页面)选择视图-->页眉和页脚-->设置为取消链接到前一页.设置页码格式为起始 ...

随机推荐

  1. 浏览器与服务器间的交互(客服端 <---> 服务器)

    浏览器与服务器间的交互(客服端 <---> 服务器) 请求--->处理--->响应 对类HttpContext 内部成员的使用 例如 :Request .Response .  ...

  2. windows无效字符名导致的错误及解决办法

    今天用file_put_content($fileName,$data)产生错误:内容如下: Warning: file_put_contents(images/7d5636992a7395f9174 ...

  3. HDU 4739 求正方形个数

    九野的博客,转载请注明出处:http://blog.csdn.net/acmmmm/article/details/11711707 求所有可能围成的正方形,借个代码 #include <que ...

  4. Python标准库:内置函数repr(object)

    本函数是返回对象object的具体说明字符串. 样例: #repr() print(repr(range(5))) print(repr(help)) print(repr(0x200)) print ...

  5. python package的概念

    主目录下面文件夹pack,可以按照 import pack.mo as mo 来调用模块,意为把pack文件夹当作一个包

  6. HDOJ4006 The kth great number 【串的更改和维护】

    The kth great number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Oth ...

  7. 在mac os 中安装 autoconf and automake

    转载地址:http://www.mattvsworld.com/blog/2010/02/install-the-latest-autoconf-and-automake-on-mac-os-10-6 ...

  8. git教程1

    主要参考: 官方书籍: Pro Git 中文版:http://git.perlchina.org/book/zh 英文版:http://git.perlchina.org/book http://gi ...

  9. Tinyfool的2013年总结————在困惑和挣扎中试图前行

    Tinyfool的2013年总结----在困惑和挣扎中试图前行 | Tinyfool的Blog Tinyfool的2013年总结----在困惑和挣扎中试图前行

  10. springmvc + jquery easyui实现分页显示

    如有不明确的地方,戏迎增加QQ群交流:66728073      推荐一本Java学习的书:深入理解Java7 一,下载并导入jquery easyui的导 <link rel="st ...