如何使Tableview中的分隔符(单行)透明?

发布于 2024-08-06 04:43:31 字数 97 浏览 1 评论 0原文

我在我的应用程序中使用了表视图,并且在其中使用了表视图给出的单行分隔符。 如何在表格视图中制作透明分隔符?

如果有人有任何想法/代码片段/有用的链接,我将不胜感激。

I have used table view in my application, and within that I have used the single line separator given by tableview.
How can I make a transparent separator in a tableview?

If anybody has any ideas/code snippets/useful links, I would greatly appreciate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

森林很绿却致人迷途 2024-08-13 04:43:31

这很简单
在你的 viewdidload 中使用这个

[yourTableView setSeparatorColor:[UIColor clearColor]];

it's very simple
in your viewdidload use this

[yourTableView setSeparatorColor:[UIColor clearColor]];

初心未许 2024-08-13 04:43:31

以防万一有人仍在寻找具有任何高度的“透明”分隔符的解决方案:

在自定义 UITableViewCell 内:

override func layoutSubviews() {
    super.layoutSubviews()
    let mutablePath = CGMutablePath()
    mutablePath.addRect(self.bounds)
    // frame for your separator
    let frame = CGRect(x: 0, y: 55, width: self.bounds.size.width, height: 5)
    mutablePath.addRect(frame)
    let mask = CAShapeLayer()
    mask.path = mutablePath
    mask.fillRule = CAShapeLayerFillRule.evenOdd
    self.layer.mask = mask
    if !(self.superview?.isKind(of: UITableView.self) ?? false) {
      self.superview?.layer.mask = mask
    }
  }

Just in case someone is still looking for solution with 'transparent' separator of any height:

Inside custom UITableViewCell:

override func layoutSubviews() {
    super.layoutSubviews()
    let mutablePath = CGMutablePath()
    mutablePath.addRect(self.bounds)
    // frame for your separator
    let frame = CGRect(x: 0, y: 55, width: self.bounds.size.width, height: 5)
    mutablePath.addRect(frame)
    let mask = CAShapeLayer()
    mask.path = mutablePath
    mask.fillRule = CAShapeLayerFillRule.evenOdd
    self.layer.mask = mask
    if !(self.superview?.isKind(of: UITableView.self) ?? false) {
      self.superview?.layer.mask = mask
    }
  }
转身以后 2024-08-13 04:43:31

只需使用
tableView.separatorColor = .clear

Just use
tableView.separatorColor = .clear

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文