-2

enter image description here

I have taken UITableview section header and other cell to display contents but when it comes to give corner radius how can we achieve such layout with out having any pain.

I have tried to give corner radius to tableview header for from topLeft,topRight and last cell to bottomLeft,bottomRight but it didn't work for me.

 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()
    }

Thank you for your help.

Anil Kukadeja
  • 1,348
  • 1
  • 14
  • 27

2 Answers2

0

use Disclouser tableviewcell for Cells and section header for Top Header

Nimit
  • 145
  • 1
  • 8
-2

You can change de backgroundView of the TableViewCell, create a subclass of UIView and change the layer class:

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

later in cellForRowAtIndexPath you do something like this:

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
PPL
  • 6,357
  • 1
  • 11
  • 30