我可以在UITableViewCell之间留出空间吗?

Tar*_*era 9 iphone objective-c uitableview ios

我想在每个表视图单元格中给出10个像素的空间.

我怎么能这样做?

现在所有的细胞都没有任何空间

在此输入图像描述

这是我的细胞功能

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

  static NSString *cellIdentifier = @"MyOrderCell";
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

  NSLog(@"%d",indexPath.row);


 if (cell == nil)
 {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
 }



 UILabel *orderid = (UILabel*)[cell.contentView viewWithTag:101];
 orderid.textColor = kMaroonColor;
 orderid.font = [UIFont fontWithName:kFontName size:kProductFont];
 orderid.text = [NSString stringWithFormat:@"ORDER ID : %@",contentDict[@"order_id"]];

 UILabel *date = (UILabel*)[cell.contentView viewWithTag:102];
 date.textColor = kMaroonColor;
 date.font = [UIFont fontWithName:kFontName size:kProductFont];

 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
 [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
 NSDate *date1 = [dateFormat dateFromString:contentDict[@"order_date"]];

 // Convert date object to desired output format
 [dateFormat setDateFormat:kDateFormat1];
 NSString *dateStr = [dateFormat stringFromDate:date1];
 date.text = dateStr;

 NSArray *products = contentDict[@"products"];
 UILabel *noOfProducts = (UILabel*)[cell.contentView viewWithTag:103];
 noOfProducts.textColor = kMaroonColor;
 noOfProducts.font = [UIFont fontWithName:kFontName size:kProductFont];
 noOfProducts.text= [NSString stringWithFormat:@"NO OF PRODUCTS : %d",products.count];


 NSArray *totalArray = contentDict[@"totals"];
 NSDictionary *totalDict = [totalArray objectAtIndex:0];
 UILabel *price = (UILabel*)[cell.contentView viewWithTag:104];
 price.textColor = [UIColor blackColor];
 price.font = [UIFont fontWithName:kFontName size:kProductFont];
 NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"\u20B9 %@",totalDict[@"total"]]];
 [attributeString addAttribute:NSForegroundColorAttributeName
                        value:kGreyColor
                        range:NSMakeRange(0, 1)];
 price.attributedText = attributeString; 

 UIView* shadowView = [[UIView alloc]init];
 [cell setBackgroundView:shadowView];
 // border radius
 [shadowView.layer setCornerRadius:10.0f];

 // border
 [shadowView.layer setBorderColor:[UIColor lightGrayColor].CGColor];
 [shadowView.layer setBorderWidth:1.5f];

 // drop shadow
 [shadowView.layer setShadowColor:[UIColor blackColor].CGColor];
 [shadowView.layer setShadowOpacity:0.8];
 [shadowView.layer setShadowRadius:3.0];
 //[cell.layer setShadowOffset:CGSizeMake(5.0, 5.0)];
 [tableView setSeparatorInset:UIEdgeInsetsMake(10, 10, 10, 10)];
 [cell setLayoutMargins:UIEdgeInsetsMake(10, 10, 10, 10)];
 //    [tableView setIndentationWidth:10];
 //    [tableView setIndentationLevel:2];

 //tableView.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
 return cell;
}
Run Code Online (Sandbox Code Playgroud)

Sah*_*Roy 10

最简单的方法是让你的细胞高度比你的细胞背景图像高一些(从顶部开始3pt,从底部开始7pt),并使颜色变为[UIColor clearColor].这会产生一种错觉,即细胞间的间隙为10 pt.


Him*_*ani 6

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
      // number of cells or array count
      return 10;
    }

- (NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(NSInteger)section
    {
      return 1;
    }

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    {
      // space between cells
       return 10;
    }

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {
        UIView *view = [UIView new];
        [view setBackgroundColor:[UIColor clearColor]];
        return view;
    }
Run Code Online (Sandbox Code Playgroud)

  • 这不是一个好的解决方法,因为大多数实现只在一个部分内使用多个单元格。 (2认同)