我想在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);
}
}
,如果你使用的便利性就像你可以擺脫大量代碼的'+ [UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:]',然後填充貝塞爾路徑,然後撫摸貝塞爾路徑。然後只需在想要不同顏色的線條上劃線即可。 –