【问题标题】:How to set corner radius within drawRect [duplicate]如何在drawRect中设置角半径[重复]
【发布时间】:2014-06-18 08:49:57
【问题描述】:

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

【问题讨论】:

  • 不是重复的 - 你的建议画了一个角轮廓,不适用于我现有的对象
  • 链接没问题。您可以描边圆角矩形,也可以填充它,或者两者都可以。

标签: ios objective-c uiviewcontroller drawrect cornerradius


【解决方案1】:

请尝试以下操作:

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];

【讨论】:

  • 我仍然认为你的问题与stackoverflow.com/questions/2835448/…重复
  • 斯威夫特:fillColor.setFill();让 path = UIBezierPath(roundedRect: rect,cornerRadius:cornerRadius); path.fill();
猜你喜欢
  • 1970-01-01
  • 2021-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-02
  • 1970-01-01
相关资源
最近更新 更多