如何将底部边框添加到 tableview 部分标题 [英] How to add bottom border to tableview section header
本文介绍了如何将底部边框添加到 tableview 部分标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下函数来确定我的应用程序中的 tableview 部分标题:
I'm using the following function to determine the tableview section header in my app:
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?{
var title: UILabel = UILabel()
title.text = "something"
// Add a bottomBorder
var border = UIView(frame: CGRectMake(0,0,self.view.bounds.width,1))
border.backgroundColor = UIColor.redColor()
title.addSubview(border)
}
和以下部分来确定tableview部分标题高度:
and the following section to determine the tableview section header height:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
如何为该部分添加底部边框?
How can I add a bottom border to the section?
推荐答案
您可以创建 UIView 作为边框,然后添加它:
You can create UIView which will act as a border and then add it:
var border = UIView(frame: CGRectMake(0,40,self.view.bounds.width,1))
border.backgroundColor = UIColor.redColor()
headerView.addSubview(border)
headerView
是您实际创建的自定义视图
headerView
is your custom view that you actually create
编辑
var headerView = UIView(frame: CGRectMake(0,0,self.view.bounds.width,40))
var title = UILabel(frame: CGRectMake(0, 0, 200, 21))
title.text = "something"
// Add a bottomBorder
var border = UIView(frame: CGRectMake(0,39,self.view.bounds.width,1))
border.backgroundColor = UIColor.redColor()
headerView.addSubview(border)
headerView.addSubview(title)
return headerView
编辑
CGRectMake
在 Swift 3.0 中不再可用.使用 CGRect
代替
CGRectMake
is not available anymore from Swift 3.0. Use CGRect
instead
这篇关于如何将底部边框添加到 tableview 部分标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文