如何在Swift中的UITableview上设置带有颜色的右边,左边,上边和下边框?
谢谢,
答案 0 :(得分:42)
尝试使用全边框:
yourtable.layer.masksToBounds = true
yourtable.layer.borderColor = UIColor( red: 153/255, green: 153/255, blue:0/255, alpha: 1.0 ).CGColor
yourtable.layer.borderWidth = 2.0
这是针对底部边框的:
let border = CALayer()
let width = CGFloat(2.0)
border.borderColor = UIColor.darkGrayColor().CGColor
border.frame = CGRect(x: 0, y: yourtable.frame.size.height - width, width: yourtable.frame.size.width, height: yourtable.frame.size.height)
border.borderWidth = width
yourtable.layer.addSublayer(border)
yourtable.layer.masksToBounds = true
答案 1 :(得分:3)
如果您想使用代码下面的颜色使用边框到tableview 对于swift 3:
yourTableView.layer.borderColor = UIColor.gray.cgColor
yourTableView.layer.borderWidth = 1.0