如何在drawRect中设置圆角半径

问题描述:

我的drawRect方法中的以下代码在我的视图控制器上绘制了一个矩形。我想为此设置一个圆角半径。我错过了什么?如何在drawRect中设置圆角半径

CGRect rectangle = CGRectMake(20, 22, 280, 460); 
CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSetRGBFillColor(context, 255, 255, 255, 1.0); 
CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0); 
CGContextFillRect(context, rectangle); 
+0

不重复 - 您的建议画一个角落大纲,并不适用于我的现有对象 – lbudge

+1

的链接是好的。你可以抚摸圆角矩形,你可以填充它,或者你可以同时做两个。 – Michael

尝试以下,请:

CGRect rectangle = CGRectMake(20, 22, 280, 460); 
CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSetRGBFillColor(context, 255, 255, 255, 1.0); 
CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0); 
//CGContextFillRect(context, rectangle); 

UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect: rectangle cornerRadius:15.0]; 

[bezierPath fill]; 
+0

我仍然认为你的问题是http://*.com/questions/2835448/how-to-draw-a-rounded-rectangle-in-core-graphics-quartz-2d的重复 – Avt