iphone - 自定义分组表单元格

标签 iphone objective-c ios quartz-graphics

我正在尝试在drawRect方法中绘制分组的表格单元格。我得到以下结果,但是我有一个问题。我希望外部边框更暗,但是我似乎无法做到这一点,我确信这是我的绘图存在问题。

我喜欢单元格中间的线条的颜色,而不喜欢单元格的外边界。

编辑:

-(void)drawRect:(CGRect)rect
{
    const float kLineWidth = 3.0;

    UIColor *topLineColor = [UIColor whiteColor];
    UIColor *bottomLineColor = [UIColor colorWithRed:225.0f/255.0f green:225.0f/255.0f blue:225.0f/255.0f alpha:1.0f];
    UIColor *backgroundColor = [UIColor colorWithRed:242.0f/255.0f green:242.0f/255.0f blue:242.0f/255.0f alpha:1.0f];

    CGColorRef bottomSeparatorColorRef = [bottomLineColor CGColor];
    CGColorRef topSeparatorColorRef = [topLineColor CGColor];

    CGContextRef context = UIGraphicsGetCurrentContext();


    UIRectCorner corners = 0;

    switch(self.position) {

        case OTCellBackgroundViewPositionTop:
            corners = UIRectCornerTopLeft | UIRectCornerTopRight;
            break;

        case OTCellBackgroundViewPositionMiddle:
            break;

        case OTCellBackgroundViewPositionBottom:
            corners = UIRectCornerBottomLeft | UIRectCornerBottomRight;
            break;

        default:
            break;
    }

    [backgroundColor setFill];
    [topLineColor setStroke];

    UIBezierPath *bezierPath =   [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corners cornerRadii:CGSizeMake(10.0f, 10.0f)];

    [bezierPath fill];
    [bezierPath stroke];
    [bezierPath setLineWidth:3.0f];

    if (self.position == OTCellBackgroundViewPositionTop) {
        // Draw the Bottom Line
        CGContextSetStrokeColorWithColor(context, bottomSeparatorColorRef);
        CGContextSetLineWidth(context, kLineWidth);
        CGContextSetLineCap(context, kCGLineCapSquare);
        CGContextMoveToPoint(context, 0.0, rect.size.height);
        CGContextAddLineToPoint(context, rect.size.width, rect.size.height);
        CGContextStrokePath(context);   
    }

    if (self.position == OTCellBackgroundViewPositionBottom) {
        // Draw the Top Line
        CGContextSetStrokeColorWithColor(context, topSeparatorColorRef);
        CGContextSetLineWidth(context, kLineWidth);
        CGContextSetLineCap(context, kCGLineCapSquare);
        CGContextMoveToPoint(context, 0.0, 0.0);
        CGContextAddLineToPoint(context, rect.size.width, 0);
        CGContextStrokePath(context);
    }
}

最佳答案

您正在将顶部分隔符设置为白色。

UIColor *topLineColor = [UIColor whiteColor];
CGColorRef topSeparatorColorRef = [topLineColor CGColor];
// Top Line
CGContextSetStrokeColorWithColor(context, topSeparatorColorRef);

只需将其设置为较深的颜色即可。

关于iphone - 自定义分组表单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13214359/

相关文章:

iPhone - 使用 TEXT 主键的 SQLite

iphone - 以编程方式更改 viewDidLoad() 中 UILabel 的文本

objective-c - Apple Mach-O 链接器 (Id) 错误!!不知道该怎么办

ios - 分段控件给出数值

iphone UITable reloadRowsAtIndexPaths 很奇怪的问题

ios - Swift:向下转换硬拷贝对象,获得实例变量的默认值?

iphone - HoughCircles 给出了错误的圈数和位置 - iOS

objective-c - 下载没有 NSUrl/CFNetwork 的文件

ios - 谷歌地图 SDK : Draw correct polyline in google map as Device Moves in Background

ios - 有人可以向我解释 initWithNibName 在 iOS 中的用法吗?