【问题标题】:UITableView with static cell - different separation color per section?带有静态单元格的 UITableView - 每个部分的分隔颜色不同?
【发布时间】:2012-07-22 12:37:28
【问题描述】:

我有 UITableView,其中包含在 Storyboard 中完成的 4 个部分中的静态单元格。但是,我想更改一个部分的分隔符颜色([UIColor clearColor])。我怎样才能做到这一点???真的可以吗?

我可以将整个表格的 separatorColor 设置为 clearColor,但不仅限于一个特定的部分。

表格视图部分的屏幕截图:

【问题讨论】:

    标签: objective-c ios uitableview


    【解决方案1】:

    AFAIK 没有办法做到这一点。但是您可以将背景图像放在底部有分隔符的单元格中,并将 separatorstyle 设置为 UITableViewCellSeparatorStyleNone。因此,您在每个单元格中都有自己的分隔符。

    【讨论】:

    • 我在 iphonesdk.com 论坛上问过,Manish915 回复了我,还附上了截图,所以我想应该没那么难iphonedevsdk.com/forum/iphone-sdk-development/…
    • 我不确定,但你可以试试。无论如何,您的 cellForRowAtIndexPath 方法应该像这样开始: static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; }
    【解决方案2】:

    也许您可以通过将部分的标题文本设置为空字符串来实现您的目标。

    【讨论】:

      【解决方案3】:

      一种方法是创建您自己的UIView 子类并在drawRect: 中进行您自己的自定义绘图。您将采用此视图并将其添加为表格视图单元格的backgroundView。像这样的:

      - (void)drawRect:(CGRect)rect
      {
          [super drawRect:rect];
          // Drawing code
          CGContextRef context = UIGraphicsGetCurrentContext();
          CGContextSetLineWidth(context, 1.0);
      
          // Draw black line
          CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
          CGFloat components[] = {0.0, 0.0, 0.0, 0.3};
          CGColorRef blackColor = CGColorCreate(colorspace, components);
      
          CGContextSetStrokeColorWithColor(context, blackColor);
      
          CGContextMoveToPoint(context, 0, rect.size.height - 1.5);
          CGContextAddLineToPoint(context, rect.size.width, rect.size.height - 1.5);
          CGContextStrokePath(context);
          CGColorRelease(blackColor);
      
          // Draw white bottom line
          CGFloat whiteComponents[] = {1.0, 1.0, 1.0, 0.75f};
          CGColorRef whiteColor = CGColorCreate(colorspace, whiteComponents);
      
          CGContextSetStrokeColorWithColor(context, whiteColor);
      
          CGContextMoveToPoint(context, 0, rect.size.height - 0.5);
          CGContextAddLineToPoint(context, rect.size.width, rect.size.height - 0.5);
          CGContextStrokePath(context);
          CGColorRelease(whiteColor);
      
          // Draw top white line
          CGFloat whiteTransparentComponents[] = {1.0, 1.0, 1.0, 0.45};
          CGColorRef whiteTransparentColor = CGColorCreate(colorspace, whiteTransparentComponents);
      
          CGContextSetStrokeColorWithColor(context, whiteTransparentColor);
      
          CGContextMoveToPoint(context, 0, 0.5);
          CGContextAddLineToPoint(context, rect.size.width, 0.5);
          CGContextStrokePath(context);
          CGColorRelease(whiteTransparentColor);
      
      
      
          CGColorSpaceRelease(colorspace);
      }
      

      【讨论】:

        猜你喜欢
        • 2013-01-16
        • 1970-01-01
        • 1970-01-01
        • 2012-12-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-05
        • 1970-01-01
        相关资源
        最近更新 更多