2
我在iOS上繪製了一個圓角矩形。CGContextStrokeRectWithWidth具有內部舍入?
這個矩形有一個圖像背景,我用貝塞爾路徑剪裁,然後繪製一個寬度爲兩個像素的筆畫。
我的問題是筆畫在裏面有鋒利的邊緣,而不是似乎跟隨圓角矩形路徑。
下面是我增加了白色以顯示我正在處理的問題的屏幕截圖。
這裏是我的代碼:
CGContextRef context = UIGraphicsGetCurrentContext();
CGPathRef strokeRect = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:2].CGPath;
CGContextAddPath(context, strokeRect);
CGContextClip(context);
// draw background
[[UIImage imageNamed:@"background.png"] drawInRect:rect];
// draw stroke
CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 0.1);
CGContextStrokeRectWithWidth(context, rect, 2);