2014-02-11 215 views

回答

6

你可以通过设置你的背景,你想要的任何背景(假设灰色在这种情况下)做到这一点,在细胞中,添加一个白色的UIView与左,右和下边缘是这样的:

enter image description here

然后转到您的表视图,设置分隔符为无

enter image description here

和最后一步,设置你的表视图的背景,相同的灰色背景为您的电池。

enter image description here

然后,你不必做任何事情,特别是在你的代码除了简单地基于自定义笔尖文件最初的表格单元格(我假设你无论如何要做到这一点)。

如果你喜欢用代码构造你的单元格,你可以使用相同的逻辑。

0

一种方式将是对的UITableViewCell的backgroundView设置为在方法含有对灰色背景

1

此白盒的的UIImageView:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    ... 

    cell.backgroundColor = [UIColor whiteColor]; 

    // This will create a line of 3 pixels that will be separating the cells 
    UIView *separator = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,3)]; 
    separator.backgroundColor = [UIColor darkGrayColor]; 
    [cell.contentView addSubview: separator]; 

    // and if you want the border do left and right add: 
    UIView *separatorRx = [[UIView alloc] initWithFrame:CGRectMake(318,0,2,cell.frame.size.height)]; 
    separatorRx.backgroundColor = [UIColor darkGrayColor]; 
    [cell.contentView addSubview: separatorRx]; 

    UIView *separatorSx = [[UIView alloc] initWithFrame:CGRectMake(0,0,2,cell.frame.size.height)]; 
    separatorSx.backgroundColor = [UIColor darkGrayColor]; 
    [cell.contentView addSubview: separatorSx]; 

    return cell; 

} 

enter image description here

0

你必须创建一个UITableViewCell的子类。在你自己的子类中,你可以创造你梦寐以求的一切!因此,您需要将UIViewwhiteColor背景和边距作为您自定义UITableViewCell的子视图添加。

0

UITableView中没有填充选项。您可以在您的UITableViewCell中添加UIView,其中包含所有单元格子视图,并更改它的框架以在单元格中创建填充权限。

建议您使用UICollectionView来代替,您可以使用布局轻松设置单元格之间的空间。如果单元格小于实际的集合视图,则它会自动居中。

相关问题