gpt4 book ai didi

iphone - 自定义分组表单元格

转载 作者:行者123 更新时间:2023-12-01 16:54:17 25 4
gpt4 key购买 nike

我正在尝试在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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com