Rounded corners in a UITableView (iOS7)

拜拜、爱过 提交于 2019-11-28 19:13:06
Hussain Shabbir

Your UITableview contains UIView, so just use this below lines of code for making it rounded corners. Also write this below line of code inside your tableview methods

//If iOS version < 10

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

//If iOS version >= 10

For Objective-C:

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

For Swift:

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

Note: No need to import QuartzCore framework explicitly.

I subclassed UITableViewCell and had to leave out contentView to make it work.

cell.layer.cornerRadius = 10 cell.layer.maskToBounds = true

Use below...

[cell.contentView.layer setCornerRadius:7.0f];
[cell.contentView.layer setMasksToBounds:YES];

try table view delegate

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.layer.cornerRadius = 10;
    cell.layer.masksToBounds = YES;
}

Note/Recommend: Better use Cell XIB/NIB file, add a UIView with keeping top, bottom, left & right corners margin via constraints, keep cell background transparent and round UIView corners. My solution was good at that situation. But Always go for best practices.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!