2

UITableView

  • 样式 -> 分组
  • 分隔符 -> 信号线蚀刻清晰的颜色

截屏

在此处输入图像描述

没关系,但我想改变单元格下“阴影”的颜色。我想我已经尝试了所有的背景颜色、色调、阴影颜色等,但什么都没有……有人可以帮我吗?

4

2 回答 2

3

好的,我找到了解决方案。我已将分隔符样式更改为无并为每个单元格的图层添加阴影

cell.layer.shadowColor = [[UIColor redColor] CGColor];
cell.layer.shadowOpacity = 1.0;
cell.layer.shadowRadius = 0;
cell.layer.shadowOffset = CGSizeMake(0.0, 1.0);
于 2013-04-17T08:05:04.880 回答
0

您可以将UITableViewCell您正在使用的子类化并以任何您想要的方式对其进行自定义。然后,当您实现您的tableView:cellForRowAtIndexPath:方法时,您只需将单元格设置为您的自定义单元格之一,如下所示:

static NSString *CellIdentifier = @"ExampleCell";
MyCustomTableViewCell *cell = (MyCustomTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
  cell = [[MyCustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
 }
return cell;

然后是自定义文件中单元格的示例MyCustomTableViewCell.m

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {


    self.clipsToBounds = YES;

    UIView* bgView = [[UIView alloc] init];
    bgView.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.25f];
    self.selectedBackgroundView = bgView;

    self.textLabel.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]];
    self.textLabel.shadowOffset = CGSizeMake(0, 2);
    self.textLabel.shadowColor = [UIColor colorWithWhite:0 alpha:0.25];

    UIView *topLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 1)];
    topLine.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.25];
    [self.textLabel.superview addSubview:topLine];

    UIView *bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 200, 1)];
    bottomLine.backgroundColor = [UIColor colorWithWhite:0 alpha:0.25];
    [self.textLabel.superview addSubview:bottomLine];

  }
  return self;
}

这使您看起来像:这个. 抱歉图片太窄了,但我没有时间重做整个事情来获得一个宽单元格。

于 2013-04-13T16:10:25.150 回答