简体   繁体   中英

Adding space between UITableView cells and making them round cornered

I have a UItableView in which I am loading RSS. I would like to leave a space between each cell in the table view, as well as giving round corners to each cell, to give an effect like this one:

在此处输入图片说明

The problem is that I can't seem to find working code. Using:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 10.; // you can have your own choice, of course
}

only adds space on top of the UITableView...

创建此UI的最简单方法是创建一个自定义UITableViewCell ,该UITableViewCell在底部将具有额外的空间,如果您可以创建一个.png文件,该文件将是带有圆角的灰色背景,或者可以使用view.layer.cornerRadius进行圆角处理view.layer.cornerRadius (不要忘了在QuartzCore中包括QuartzCore ),添加标签和箭头即可。

No need to customize anything.

You have to initialize your tableView with a "groupedStyle". Or, if you you're using storyboard, set the style there. Then make the tableView background color to whatever you want.

myTableViewContoller = [[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped];

the heightForHeaderInSection thing is for sections, not rows. you can do heightForRowAtIndexPath if you really need to for some reason.

You can first make cells to be clear color background, then add a rounded corner view which should be smaller than the cell. This makes it looks like it gets a spacing around the cell.

This is an older one, but I ran into this problem recently. If your cells have a custom uiTableViewCell class add this to the bottom of the .m file of the class (just above @end)

- (void)setFrame:(CGRect)frame {
    frame.origin.y += 4;
    frame.size.height -= 2 * 5;  //adds the space and gives a 5 point buffer, can also indent the width using frame.size.width
    [super setFrame:frame];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM