0
我正在使用繪製矩形繪製帶有圓角半徑的矩形。代碼完美工作。在4英寸屏幕上查看時,您會看到矩形。在3.5英寸屏幕上查看時,矩形不會調整大小並從屏幕底部運行。任何指針?drawRect不會調整大小和運行屏幕3.5英寸屏幕
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect rrect = CGRectMake(20, 30, 280, 515);
CGFloat radius = 7;
CGFloat minx = CGRectGetMinX(rrect), midx = CGRectGetMidX(rrect), maxx = CGRectGetMaxX(rrect);
CGFloat miny = CGRectGetMinY(rrect), midy = CGRectGetMidY(rrect), maxy = CGRectGetMaxY(rrect);
// Start at 1
CGContextMoveToPoint(context, minx, midy);
// Add an arc through 2 to 3
CGContextAddArcToPoint(context, minx, miny, midx, miny, radius);
// Add an arc through 4 to 5
CGContextAddArcToPoint(context, maxx, miny, maxx, midy, radius);
// Add an arc through 6 to 7
CGContextAddArcToPoint(context, maxx, maxy, midx, maxy, radius);
// Add an arc through 8 to 9
CGContextAddArcToPoint(context, minx, maxy, minx, midy, radius);
// Close the path
CGContextClosePath(context);
CGContextSetStrokeColorWithColor(context, [[UIColor whiteColor] CGColor]);
CGContextSetRGBFillColor(context, 255, 255, 255, 1.0);
// Fill & stroke the path
CGContextDrawPath(context, kCGPathFillStroke);
}
爲什麼當您使用硬編碼大小時,矩形會調整大小?如果您想調整其大小,請根據屏幕尺寸(或更好的是,您繪製的視圖尺寸)來確定寬度和高度。 – Putz1103