Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create tableview with rounded corners

I was trying to create rounded corner for tableview using UIBezierPath and its not working and so far the better way seems to be have the tableview inside a view and round the corner for the view rather than tableview.

Does anybody have a better way of doing it

like image 607
Ranjith kumar Avatar asked Oct 28 '25 08:10

Ranjith kumar


2 Answers

To round the UITableView's corners,

1. Make sure UITableViewCell's clipToBounds is selected in Storyboard.

2. Make sure UITableView's clipToBounds is selected in Storyboard.

enter image description here

3. Set cornerRadius value of UITableView's layer, i.e.

@IBOutlet weak var tableView: UITableView!

override func viewDidLoad()
{
    super.viewDidLoad()
    self.tableView.layer.cornerRadius = 10.0
}

Screenshot:

enter image description here

like image 161
PGDev Avatar answered Oct 29 '25 22:10

PGDev


If you need rounded corners for your table view rows check this link

For Objective-c:--

   cell.contentView.layer.cornerRadius = 5;
   cell.contentView.layer.masksToBounds = YES;

For Swift:--

cell.contentView.layer.cornerRadius = 5
cell.contentView.layer.masksToBounds = true

For whole tableview try this link

#import <QuartzCore/QuartzCore.h>

 self.tableView.layer.borderColor = [UIColor colorWithWhite:0.6 alpha:1].CGColor;   
 self.tableView.layer.borderWidth = 1;
 self.tableView.layer.cornerRadius = 4;
like image 35
Cintu Avatar answered Oct 29 '25 21:10

Cintu