Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ios:如何在tableview中添加上下边框?_Ios_Uitableview - Fatal编程技术网

ios:如何在tableview中添加上下边框?

ios:如何在tableview中添加上下边框?,ios,uitableview,Ios,Uitableview,我想要像这张图片一样的表格,只显示颜色的上下边框 我已经在viewDidLoad()中应用了此代码 上面的代码在所有我不想要的边上添加边框。 我只想在顶部或底部的表边框。 我想要像给定图像一样的tableview边框。查看给定的图像。 请给我建议解决办法 谢谢 试试这个 let topBorder = CAShapeLayer() let topPath = UIBezierPath() topPath.move(to: CGPoint(x: 0, y: 0))

我想要像这张图片一样的表格,只显示颜色的上下边框

我已经在viewDidLoad()中应用了此代码

上面的代码在所有我不想要的边上添加边框。 我只想在顶部或底部的表边框。 我想要像给定图像一样的tableview边框。查看给定的图像。 请给我建议解决办法 谢谢

试试这个

    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)

如果不想使用表页脚和页眉,您可以使用表页眉视图和页脚视图,其中您可以返回白色的视图,高度为1,宽度与表宽度相同

使用表页眉和页脚

// in -viewDidLoad
self.tableView.tableHeaderView = ({UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 1 / UIScreen.mainScreen.scale)];
    line.backgroundColor = self.tableView.separatorColor;
    line;
});
同样,对页脚也要这样做

self.tableView.tableFooterView = ({UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 1 / UIScreen.mainScreen.scale)];
        line.backgroundColor = self.tableView.separatorColor;
        line;
    });

或者只需将UIVIEW添加到背景并设置颜色。这也会有帮助。

看两遍。给它白色。 顶部uiview的y坐标系是uitableview的最小y坐标系,底部uiview的y坐标系是uitableview的最大y坐标系

您可以使用
GetMaxY
GetMinY
获取最小y和最大y

两个uiview的宽度与uitableview相同

两个uiview的高度均为1px


希望这会对您有所帮助。

在单元格中选择高度值为1的标签,并给它加上边框。以编程方式隐藏/显示所需索引。

我的问题已解决。
我添加了一个自定义视图。在该视图中,我在视图的顶部和底部添加了两个高度为1px的视图,并在该自定义视图中添加了表格视图。

您可以使用高度和宽度与表格相同的uiview。设置uiview的背景色我是ios新手,如何在顶部和底部添加uiview?试试这个:只需减小x并增加宽度就可以了,你只会得到顶部和底部添加的边框,但当我滚动我的tableview时,它会滚动。我不想滚动边框。它应该粘在顶部和底部。我应用下面的代码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)谢谢,但当我滚动我的表格时,请查看它的滚动。我要在顶部和底部进行修复。我做什么?在最后一行“btn”是什么意思?感谢它的工作,但当我滚动tableview时,为什么这一行与它们一起滚动。我不想滚动它。边框仍在滚动。。我做什么@Rajeshkumar Rbut试着去理解。根据您的代码,视图已添加到tableview的顶部,但当我滚动表格时,边框也会随之滚动,这是我不想要的。我需要在顶部或底部粘贴边框。我这样做了,但它与表格内容一起滚动。我想要在顶部和底部进行修复。但是如何停止滚动?在单元格内,您要求粘贴所有4个约束顶部、底部、前导、尾随。不,我想要表格视图的顶部和底部边框,我已经完成了,但是当我滚动表格视图时,我的表格边框会滚动,所以,如何停止边框滚动
self.tableView.tableFooterView = ({UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 1 / UIScreen.mainScreen.scale)];
        line.backgroundColor = self.tableView.separatorColor;
        line;
    });