如何在drawRect中设置角半径

时间:2014-05-01 19:31:12

标签: ios objective-c uiviewcontroller drawrect cornerradius

我的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);

1 个答案:

答案 0 :(得分:5)

请尝试以下:

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];
相关问题