Đoạn mã dưới đây tạo ra hình chữ nhật tròn được xác định bởi một CGRect (rectRect).Đường nét không thể đột quỵ sau khi điền vào
Nó lấp đầy, nhưng tôi không bị đột quỵ. Bất kỳ ý tưởng tại sao tôi không thể nhìn thấy đột quỵ?
-(void)drawRect:(CGRect)rect {
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(ctx, 0, 0, 0, 0.4);
CGContextSetRGBStrokeColor(ctx, 1, 1, 1, 1);
CGContextSetLineWidth(ctx, 4.0);
float fw, fh;
rect = rectRect;
float ovalWidth = 12;
float ovalHeight = 12;
if (ovalWidth == 0 || ovalHeight == 0) {
CGContextAddRect(ctx, rect);
return;
}
CGContextTranslateCTM (ctx, CGRectGetMinX(rect), CGRectGetMinY(rect));
CGContextScaleCTM (ctx, ovalWidth, ovalHeight);
fw = CGRectGetWidth (rect)/ovalWidth;
fh = CGRectGetHeight (rect)/ovalHeight;
CGContextMoveToPoint(ctx, fw, fh/2);
CGContextAddArcToPoint(ctx, fw, fh, fw/2, fh, 1);
CGContextAddArcToPoint(ctx, 0, fh, 0, fh/2, 1);
CGContextAddArcToPoint(ctx, 0, 0, fw/2, 0, 1);
CGContextAddArcToPoint(ctx, fw, 0, fw, fh/2, 1);
CGContextClosePath(ctx);
CGContextFillPath(ctx);
CGContextStrokePath(ctx);
}
Cảm ơn. Đây là những gì tôi đang tìm kiếm. – Mrwolfy
Oh nhân tiện, tùy chọn UIBezierPath có khắc phục hiệu suất cao không? Nó hoạt động hoàn hảo tất nhiên. Hoặc tôi nên tìm ở nơi khác. – Mrwolfy
Đừng lo lắng về hiệu suất cho đến khi Dụng cụ cho bạn biết nơi bị tắc nghẽn. –