美文网首页Swift学习
swift之sb的TableView控件静态设置自定义样式

swift之sb的TableView控件静态设置自定义样式

作者: Seizens_Swift | 来源:发表于2015-08-11 22:28 被阅读665次

1. 建立项目<code>SwiftSBCustomTableView</code>项目

如下图所示:

Paste_Image.png

2. 建立<code>SwiftSBCustomTableViewController.swift</code>和sb文件中的TableView视图

如图所示为添加TableView到sb中

Paste_Image.png

这时将tableView视图与<code>SwiftSBCustomTableViewController.swift</code>关联起来。如图所示:

Paste_Image.png

下来就对sb文件中的TableView来设置了。

3.对sb文件中TableView进行设置

1.将<code>tableview</code>的<code>Content</code>选择<code>Static Cells</code>,在将<code>Secitons</code>设置为4,这里的设置可以根据自己的情况来设置。如下图所示:

Paste_Image.png

当这是设置完毕后会出现如下图所示的效果了

Paste_Image.png

下来就来开始设置对应的样式了

4.添加自定义的样式

  1. 现在就可以直接拖控件到各自的cell中去了。如下图所示,是我对应的设置的控件
Paste_Image.png

这就是我向其中添加的控件,大家可以自己随意的向其中添加自己所需要的控件

5.在<code>ViewController.swift</code> 实现该界面

添加的代码如下所示:
<code>
// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 4
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    switch section {
    
    case 0:
        return 3
    case 1:
        return 2
    case 2:
        return 2
    default:
        return 2
    }
}

</code>

结果如下图所示:

Paste_Image.png

介绍完毕,详细代码请到此处下载:http://pan.baidu.com/s/1hq4df1q

相关文章

网友评论

    本文标题:swift之sb的TableView控件静态设置自定义样式

    本文链接:https://www.haomeiwen.com/subject/ncmiqttx.html