ios - 我可以在 UITableViewCell 之间留出空间吗

标签 ios objective-c iphone uitableview

我想在每个表格 View 单元格中留出 10 像素的空间。

我该怎么做?

现在所有的细胞都在没有任何空间的情况下出现

enter image description here

这是我的细胞功能

- (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;
}

最佳答案

最简单的方法是让你的单元格高度比你单元格的背景图像大一点(从顶部开始 3pt,从底部开始 7pt),并将颜色设置为 [UIColor clearColor] .这会给人一种错觉,即细胞之间有 10 pt 的间隙。

关于ios - 我可以在 UITableViewCell 之间留出空间吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36418492/

相关文章:

iphone - 获取 iPod 库中项目的专辑年份?

objective-c - UIButton 点击​​没有响应

ios - 如何在 ios objective c 中使用 uigesturerecognizer 滑动自定义五个 subview

ios - 如何制作没有 xib 或 Storyboard vc 标识符的 View Controller ?

iphone - 无法使用 Fonemonkey 运行测试

iphone - navigationItem.backBarButtonItem 不工作?为什么以前的菜单仍然显示为按钮?

ios - 快速使用 Spotify SDK 的编译器错误

ios - 在 calloutAccessoryControlTapped 上检测仅点击 rightCalloutAccessoryView

ios - 谷歌地图 iOS 对 CalloutAccessoryView 的替换?

iphone - ios添加UICollectionView reuseIdentifier报错