2012-07-22 73 views
1

我有在Storyboard中完成的4个部分中的静态单元格的UITableView。不过,我想更改一个部分的分隔符颜色([UIColor clearColor])。我怎样才能做到这一点???它实际上可能吗?UITableView与静态单元格 - 每节不同的分离颜色?

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

截图表视图部分的:

Screenshot of table view section

回答

1

AFAIK存在用于此没有方法。但是,您可以将背景图像放置在底部有分隔符的单元格中,并将separatorstyle设置为UITableViewCellSeparatorStyleNone。所以你在每个单元格中都有自己的分隔符。

+0

我已请iphonesdk.com论坛和Manish915回答我这个连连接它的屏幕截图,所以我想这不应该是很难http://www.iphonedevsdk.com/forum /iphone-sdk-development/106224-uitablewiew-with-static-cell-different-separation-color-per-section.html – pprochazka72 2012-07-22 14:17:11

+0

我不确定,但您可以尝试。无论如何,你的cellForRowAtIndexPath方法应该像这样开始: static NSString * CellIdentifier = @“Cell”; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(!cell)cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } – Mert 2012-07-22 16:52:43

0

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

0

一种方法是创建自己的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); 
} 
相关问题