下面的简单UIView绘制了一个圆角矩形。当我通过65或以下的拐角半径时,它会正确倒圆,但在66或以上时会产生一个完美的圆!这里发生了什么?仅当拐角半径等于框架宽度的1/2时,才应显示一个圆,但无论视图大小如何,似乎在半径约为1/3时都将绘制一个圆。此行为出现在iOS 7上。在iOS 6上,我得到了预期的行为。
#import "ViewController.h"
@interface MyView : UIView
@end
@implementation MyView
-(void)drawRect:(CGRect)rect {
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 200, 200) cornerRadius:65];
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextAddPath(c, path.CGPath);
[[UIColor redColor] set];
CGContextStrokePath(c);
}
@end
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
MyView *v = [[MyView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[self.view addSubview:v];
}
@end
Run Code Online (Sandbox Code Playgroud)


这是我当前的代码:
override func viewDidLoad() {
super.viewDidLoad()
let rect = Draw(frame: CGRect(
origin: CGPoint(x: 50, y: 50),
size: CGSize(width: 100, height: 100)))
self.view.addSubview(rect)
}
Run Code Online (Sandbox Code Playgroud)