How to create UITableView section view with Corner radius

uitableview grouped section border
uitableview rounded corners swift 4
corner radius swift
uitableview inset grouped corner radius
rounded corner view ios swift
ios view corner radius top
xamarin forms frame corner radius only top
layer cornerradius not working

I searched lot of post related to my questions on stack overflow and other developer sites but i am unable to find exact and fit answer for that. I need to create section view of table with corner radius with out third party framework , similar like Grouped tableview styled in iOS 6.

Please help !!!

Want to like this

Try following:

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 50)];
    [view setBackgroundColor:[UIColor orangeColor]];
    [view fnForMakingRoundCorners];

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, tableView.frame.size.width, 18)];
    [label setText:@"Text"];
    [view addSubview:label];

    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {

    return 50.0f;
}

for making round corners i have written UIView category for all views as:

// For -> Rounded Corners
-(void)fnForMakingRoundCorners {

    self.layer.cornerRadius = 5.0f;
    self.layer.masksToBounds = YES;
}

will look like:

Corner Radius to UITableview Grouped - Jigar M, I got one better solution for provide a corner radius to UITablewview Grouped. Question is : I have a main view controller. It contains a table view ( in a container ). This is UITableview is Grouped Type tableview and i want to Provide the Corner of Grouped How To Create a Custom Action for the Center Tab Bar Item​. Step 1 − Open Xcode → New Project → Single View Application → Let’s name it “TableViewWithRoundedCorner” Step 2 − Open Main.storyboard and add UITableView as shown below, Step 3 − In ViewController.swift now create, @IBoutlet of tableview from Main.storyboard and name it tableView.

I think one of the option will be adding a containerView(customView) inside the section header and do the corner radius settings on it.

UITableViewHeaderFooterView *footerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"identifier"];
UIView *customView = (UIView *)[footerView viewWithTag:888];

if(footerView == nil){ // using a non-registered header
   // initialize footerView
   // <FooterView initialized>
   footerView.contentView.backgroundColor = [UIColor clearColor];
   footerView.backgroundView = nil; 

   customView = [UIView new];
   customView.tag = 888;
   [customView layer].cornerRadius = 5;
   [footerView.contentView addSubview: customView];
}

Create Rounded Sections in UITableView · GitHub, func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { let cornerRadius : CGFloat = 12.0 cell. The view has the same width as the tableView, and it has the corner radius you are just not seeing this as the view goes out of screen on the right side. Solution. In order to have your view in the middle of the screen you set its center to the contentView's center. And work with the width to set padding. Your code solution:

add this for table view

    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        let cornerRadius: CGFloat = 10
        cell.backgroundColor = .clear

        let layer = CAShapeLayer()
        let pathRef = CGMutablePath()
        let bounds = cell.bounds.insetBy(dx: 0, dy: 0)
        cornerLayerWidth = bounds.width
        var addLine = false



        if indexPath.row == 0 && indexPath.row == tableView.numberOfRows(inSection: indexPath.section) - 1 {
            pathRef.__addRoundedRect(transform: nil, rect: bounds, cornerWidth: cornerRadius, cornerHeight: cornerRadius)
        }
        else if indexPath.row == 0 {
            pathRef.move(to: .init(x: bounds.minX, y: bounds.maxY))
            pathRef.addArc(tangent1End: .init(x: bounds.minX, y: bounds.minY), tangent2End: .init(x: bounds.midX, y: bounds.minY), radius: cornerRadius)
            pathRef.addArc(tangent1End: .init(x: bounds.maxX, y: bounds.minY), tangent2End: .init(x: bounds.maxX, y: bounds.midY), radius: cornerRadius)
            pathRef.addLine(to: .init(x: bounds.maxX, y: bounds.maxY))
            addLine = true

            cell.backgroundColor = .white

        }
        else if indexPath.row == tableView.numberOfRows(inSection: indexPath.section) - 1 {
            pathRef.move(to: .init(x: bounds.minX, y: bounds.minY))
            pathRef.addArc(tangent1End: .init(x: bounds.minX, y: bounds.maxY), tangent2End: .init(x: bounds.midX, y: bounds.maxY), radius: cornerRadius)
            pathRef.addArc(tangent1End: .init(x: bounds.maxX, y: bounds.maxY), tangent2End: .init(x: bounds.maxX, y: bounds.midY), radius: cornerRadius)
            pathRef.addLine(to: .init(x: bounds.maxX, y: bounds.minY))
        } else {
            pathRef.addRect(bounds)
            addLine = true
        }

        layer.path = pathRef
        layer.fillColor = UIColor(white: 1, alpha: 1).cgColor

        if (addLine == true) {
            let lineLayer = CALayer()
            let lineHeight = 1.0 / UIScreen.main.scale
            lineLayer.frame = CGRect(x: bounds.minX, y: bounds.size.height - lineHeight, width: bounds.size.width , height: lineHeight)
            lineLayer.backgroundColor = tableView.separatorColor?.cgColor
            layer.addSublayer(lineLayer)
        }

        let testView = UIView(frame: bounds)
        testView.layer.insertSublayer(layer, at: 0)
        testView.backgroundColor = .clear
        cell.backgroundView = testView
    }

in case you want to include the section header also then try below one

declare cornerLayerWidth as global variable

var cornerLayerWidth:CGFloat = 0.0

    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        let cornerRadius: CGFloat = 10
        cell.backgroundColor = .clear

        let layer = CAShapeLayer()
        let pathRef = CGMutablePath()
        let bounds = cell.bounds.insetBy(dx: 0, dy: 0)
        cornerLayerWidth = bounds.width
        var addLine = false



        if indexPath.row == 0 && indexPath.row == tableView.numberOfRows(inSection: indexPath.section) - 1 {
            pathRef.__addRoundedRect(transform: nil, rect: bounds, cornerWidth: cornerRadius, cornerHeight: cornerRadius)
        }
        else if indexPath.row == 0 {


        }
        else if indexPath.row == tableView.numberOfRows(inSection: indexPath.section) - 1 {
            pathRef.move(to: .init(x: bounds.minX, y: bounds.minY))
            pathRef.addArc(tangent1End: .init(x: bounds.minX, y: bounds.maxY), tangent2End: .init(x: bounds.midX, y: bounds.maxY), radius: cornerRadius)
            pathRef.addArc(tangent1End: .init(x: bounds.maxX, y: bounds.maxY), tangent2End: .init(x: bounds.maxX, y: bounds.midY), radius: cornerRadius)
            pathRef.addLine(to: .init(x: bounds.maxX, y: bounds.minY))
        } else {
            pathRef.addRect(bounds)
            addLine = true
        }

        layer.path = pathRef
        layer.fillColor = UIColor(white: 1, alpha: 1).cgColor

        if (addLine == true) {
            let lineLayer = CALayer()
            let lineHeight = 1.0 / UIScreen.main.scale
            lineLayer.frame = CGRect(x: bounds.minX, y: bounds.size.height - lineHeight, width: bounds.size.width , height: lineHeight)
            lineLayer.backgroundColor = tableView.separatorColor?.cgColor
            layer.addSublayer(lineLayer)
        }

        let testView = UIView(frame: bounds)
        testView.layer.insertSublayer(layer, at: 0)
        testView.backgroundColor = .clear
        cell.backgroundView = testView
    }

and

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

        let cell = tableView.dequeueReusableCell(withIdentifier: "eMPOIListHeaderViewCell") as! eMPOIListHeaderViewCell

        let cornerRadius: CGFloat = 10

        let layer = CAShapeLayer()
        let pathRef = CGMutablePath()
        let bounds =  CGRect(x: 0, y: 0, width: cornerLayerWidth, height: 50)//cell.bounds.insetBy(dx: 0, dy: 0)

        pathRef.__addRoundedRect(transform: nil, rect: bounds, cornerWidth: cornerRadius, cornerHeight: cornerRadius)

        pathRef.move(to: .init(x: bounds.minX, y: bounds.maxY))
        pathRef.addArc(tangent1End: .init(x: bounds.minX, y: bounds.minY), tangent2End: .init(x: bounds.midX, y: bounds.minY), radius: cornerRadius)
        pathRef.addArc(tangent1End: .init(x: bounds.maxX, y: bounds.minY), tangent2End: .init(x: bounds.maxX, y: bounds.midY), radius: cornerRadius)
        pathRef.addLine(to: .init(x: bounds.maxX, y: bounds.maxY))



        layer.path = pathRef
        layer.fillColor = UIColor(white: 1, alpha: 1).cgColor

             let lineLayer = CALayer()
            let lineHeight = 1.0 / UIScreen.main.scale
            lineLayer.frame = CGRect(x: bounds.minX, y: bounds.size.height - lineHeight, width: bounds.size.width , height: lineHeight)
            lineLayer.backgroundColor = tableView.separatorColor?.cgColor
            layer.addSublayer(lineLayer)

        let testView = UIView(frame: bounds)
        testView.layer.insertSublayer(layer, at: 0)
        testView.backgroundColor = .clear

        cell.backgroundView = testView


        return cell

    }

How do I create a TableView with rounded corners in iOS?, Table views on iOS display a single column of vertically scrolling content, In this post we will see how we can create table view with rounded corners. tableView: UITableView, numberOfRowsInSection section: Int) -> Int  Apple has made it very easy to create views with rounded corner. All you need to do is set the cornerRadius property of a view’s layer and set clipsToBounds to true. Here is the code snippet:

TORoundedTableView on CocoaPods.org, A subclass of UITableView that styles it like the Settings app on iPad. an official version of this table view style called UITableViewStyleInsetGrouped ! where the 'edge-to-edge' style of the stock grouped UITableView doesn't make sense, of the rounded corners, for ultimate efficiency, it is recommended to create those​  it's set whole cell corner radius i want to set section wise – John Dec 24 '15 at 15:55 Then you need to add a viewForHeaderInSection to your tableView if you don´t already use it. Check the updated code.

table cell corner radius not working in iOS 13 |Apple Developer , does anyone have display issues in iOS 13 were corner radius is not But if you know a way to round some UITableViewCells that isnt that let  TORoundedTableView. A very basic subclass wrapper for UITableView that overrides the original 'edge-to-edge' philosophy by manually re-laying out all of the content views in a more narrow column. It also creates and manages the rounded corner image assets, so they can be efficiently shared amongst all cells.

Custom UITableViewCells with round corners, Open your project in XCode. At first we define a corner radius and a background color for the cell (between #import and (UIView *)tableView:(​UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView* header = nil;  In this tutorial you will learn how to add a header and a footer view to a UITableView. There are two ways that we can add the header and footer, one way is to add it in using Interface Builder and the other way is to do it with code. In this tutorial we will be using both Interface Builder as well as code. Step 1: Setup the UITableView The first thing that we need to do is to set up the

Comments
  • you would have to round the corners of the top / bottom cell ?
  • can you please provide screenshots, how exactly you want?
  • You need to create custom view and add it in header in viewforheader method,it works...
  • @SuhasPatil i added my screenshots with questions .
  • can show code as well?
  • Thanks for help mate, but i need to change in bottom too. can you suggest for that.
  • welcome, in bottom too means? you want footer to table view?
  • setting footer is just another delegate method, the round corner view is the same as above