【问题标题】:Facing design issue while applying corner radius to top and bottom cell only仅将角半径应用于顶部和底部单元时面临设计问题
【发布时间】:2018-05-11 13:24:13
【问题描述】:

我已经使用 UITableview 部分标题和其他单元格来显示内容,但是当涉及到角半径时,我们如何才能在没有任何痛苦的情况下实现这样的布局。

我试图为从 topLeft、topRight 和最后一个单元格到 bottomLeft、bottomRight 的 tableview 标题提供角半径,但它对我不起作用。

 func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

        guard let headerView = tableView.dequeueReusableCell(withIdentifier: "headerCell") as? headerCell else { return UIView() }

        headerView.labelTaskName.text = arrayTaskLists[section].first?.outcome_title
        headerView.viewContainerHeader.roundCorners([.topRight,.topLeft], radius: 10.0)
        headerView.viewContainerHeader.layoutSubviews()
        headerView.btnHeaderViewCell.tag = section
        headerView.delegate = self

        return headerView
    }

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 44
    }

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier.TaskInformationCell) as! TaskInformationCell

        cell.infoView.roundCorners([.bottomLeft,.bottomRight], radius: 10.0)
        cell.infoView.layoutSubviews()
    }

感谢您的帮助。

【问题讨论】:

  • 我同意您的问题太不完整,无法提供帮助。也就是说,考虑研究“容器视图”。在 it 周围放置一个圆角半径并插入您的表格视图。
  • 为什么它被否决了?在这里寻求任何帮助或讨论的想法不应该被否决
  • 编辑了一个问题@user770,@dfd
  • @user770 是什么意思?
  • @user770 :如果你不明白,那你为什么还投了反对票?我在这里粘贴了一个代码

标签: ios swift uitableview uitableviewsectionheader


【解决方案1】:

使用 Disclouser tableviewcell 作为 Cells 和 section header 作为 Top Header

【讨论】:

    【解决方案2】:

    你可以改变 TableViewCell 的背景视图,创建 UIView 的子类和改变图层类:

    class BackgroundView: UIView 
    {
        class var layerClass: AnyClass
        {
            return CAShapeLayer.self
        }
    }
    

    稍后在cellForRowAtIndexPath 你会这样做:

    private var CellIdentifier = "CustomCell"
    
    let cell = tableView.dequeueReusableCell(withIdentifier: CellIdentifier, for: indexPath) as? CustomCell
    let frame: CGRect? = cell?.backgroundView.frame
    cell?.backgroundView = BackgroundView(frame: frame ?? CGRect.zero)
    
    var corner: CGFloat = 20.0
    var path = UIBezierPath(roundedRect: cell?.backgroundView.bounds ?? CGRect.zero, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: corner, height: corner))
    var shapeLayer = cell?.backgroundView.layer as? CAShapeLayer
    
    shapeLayer?.path = path.cgPath
    shapeLayer?.fillColor = cell?.textLabel.backgroundColor?.cgColor
    shapeLayer?.strokeColor = UIColor.lightGray.cgColor
    shapeLayer?.lineWidth = 1.0
    
    return cell
    

    【讨论】:

    • 问题被标记为 Swift。请以正确的语言发布答案。
    • 请在 Swift 中检查相同的答案。
    猜你喜欢
    • 2021-07-04
    • 2016-11-04
    • 1970-01-01
    • 2021-07-03
    • 2019-01-29
    • 1970-01-01
    • 2017-10-15
    • 2013-11-26
    • 1970-01-01
    相关资源
    最近更新 更多