ano*_*mox 4 spacing cellpadding tableviewcell ios swift
我需要添加填充,以便在swift 2.1中每个部分的每个单元格之间留出空间
但我设法做的就是为我不想要的部分添加标题.
如何在动态表格单元格之间添加空格?
以下是添加标头的代码:
// Set the spacing between sections
override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 10
}
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = UIView()
header.backgroundColor = UIColor.clearColor()
return header
}
Run Code Online (Sandbox Code Playgroud)
这是创建表视图代码:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.tableData.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//Table view cells are reused and should be dequeued using a cell identifier.
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
let rowData = self.tableData[indexPath.row]
cell.textLabel!.text = rowData.name
cell.textLabel!.textAlignment = .Right
if let url = NSURL(string: rowData.img),
data = NSData(contentsOfURL: url)
{
cell.imageView?.image = UIImage(data: data)
}
return cell
}
Run Code Online (Sandbox Code Playgroud)
现在我的表视图看起来像这样:
更新代码和表视图:
表格视图中的单元格之间没有间距.仅在集合视图中.
你可以选择......
请改用集合视图.使它看起来像桌面视图相对容易.使用此选项可以使用项目间距.
将单元格的高度增加2个像素,并在每个单元格的顶部或底部添加一个空白区域.这会产生在它们之间增加空间的错觉.
| 归档时间: |
|
| 查看次数: |
6456 次 |
| 最近记录: |