ios:如何在tableview中添加顶部和底部边框?(ios:how to add top and bottom border in tableview?)

我希望像这个图像的表格只显示颜色的顶部和底部边框

我在viewDidLoad()中应用此代码

tblFilter.layer.borderWidth = 0.5 tblFilter.layer.borderColor = UIColor.white.cgColor

上面的代码在我不想要的所有方面添加边框。 我只希望桌面边框在顶部或底部。 我想要像给定图像的tableview边框。 看到给定的图像。 请建议我解决方案谢谢

I want table like this image that show top and bottom border with color only

i have apply this code in viewDidLoad()

tblFilter.layer.borderWidth = 0.5 tblFilter.layer.borderColor = UIColor.white.cgColor

above code add border at all side that i dont want. i want table border in only top or bottom side. i want tableview border like given image. see given image. please suggest me solution Thanks

最满意答案

尝试这个

let topBorder = CAShapeLayer() let topPath = UIBezierPath() topPath.move(to: CGPoint(x: 0, y: 0)) topPath.addLine(to: CGPoint(x: tblFilter.frame.width, y: 0)) topBorder.path = topPath.cgPath topBorder.strokeColor = UIColor.red.cgColor topBorder.lineWidth = 1.0 topBorder.fillColor = UIColor.red.cgColor tblFilter.layer.addSublayer(topBorder) let bottomBorder = CAShapeLayer() let bottomPath = UIBezierPath() bottomPath.move(to: CGPoint(x: 0, y: tblFilter.frame.height)) bottomPath.addLine(to: CGPoint(x: tblFilter.frame.width, y: tblFilter.frame.height)) bottomBorder.path = bottomPath.cgPath bottomBorder.strokeColor = UIColor.red.cgColor bottomBorder.lineWidth = 1.0 bottomBorder.fillColor = UIColor.red.cgColor tblFilter.layer.addSublayer(bottomBorder)

Try this

let topBorder = CAShapeLayer() let topPath = UIBezierPath() topPath.move(to: CGPoint(x: 0, y: 0)) topPath.addLine(to: CGPoint(x: tblFilter.frame.width, y: 0)) topBorder.path = topPath.cgPath topBorder.strokeColor = UIColor.red.cgColor topBorder.lineWidth = 1.0 topBorder.fillColor = UIColor.red.cgColor tblFilter.layer.addSublayer(topBorder) let bottomBorder = CAShapeLayer() let bottomPath = UIBezierPath() bottomPath.move(to: CGPoint(x: 0, y: tblFilter.frame.height)) bottomPath.addLine(to: CGPoint(x: tblFilter.frame.width, y: tblFilter.frame.height)) bottomBorder.path = bottomPath.cgPath bottomBorder.strokeColor = UIColor.red.cgColor bottomBorder.lineWidth = 1.0 bottomBorder.fillColor = UIColor.red.cgColor tblFilter.layer.addSublayer(bottomBorder)

更多推荐

边框,图像,code,image,border,电脑培训,计算机培训,IT培训"/> <meta name="descr