Vì vậy, tôi đang cố gắng ghi đè drawRect trong UIScrolLView của mình, tuy nhiên nó mang lại cho tôi nền đen này thay vì màu nền mà tôi đã chỉ định cho UIScrollView của mình. Tại sao điều này? Nếu tôi loại bỏ mã drawRect sau đó mọi thứ đều tốt:nền đen khi ghi đè drawRect trong UIScrollView
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
if (shouldDrawVerticalLineForProfile){
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorRef separatorColor = [UIColor colorWithRed:47.0/255.0 green:47.0/255.0
blue:47.0/255.0 alpha:1.0].CGColor;
// Add at bottom
CGPoint startPoint = CGPointMake(60, 0);
CGPoint endPoint = CGPointMake(60, 10000);
CGContextSaveGState(context);
CGContextSetLineCap(context, kCGLineCapSquare);
CGContextSetStrokeColorWithColor(context, separatorColor);
CGContextSetLineWidth(context, 5.0);
CGContextMoveToPoint(context, startPoint.x + 0.5, startPoint.y + 0.5);
CGContextAddLineToPoint(context, endPoint.x + 0.5, endPoint.y + 0.5);
CGContextStrokePath(context);
CGContextRestoreGState(context);
}
}
Tôi nghĩ rằng tài sản backgroundColor chỉ đơn giản là kết thúc tốt đẹp một CGContextAddRect và CGContextFillPath, những gì nếu bạn làm điều gì đó như thế? –
làm điều gì đó như thế nào? – xonegirlz
vẽ bgcolor theo cách thủ công bằng hai chức năng tôi đã đề cập ở trên. –