当前位置: 首页 > 编程笔记 >

iOS 如何将拐角半径应用于UIBezierPath绘制的矩形

聂风史
2023-03-14
本文向大家介绍iOS 如何将拐角半径应用于UIBezierPath绘制的矩形,包括了iOS 如何将拐角半径应用于UIBezierPath绘制的矩形的使用技巧和注意事项,需要的朋友参考一下

示例

所有4条边的角半径:

 UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(x,y,width,height) cornerRadius: 11];
[UIColor.grayColor setFill];
[rectanglePath fill];

左上边缘的拐角半径:

 UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(x,y,width,height) byRoundingCorners: UIRectCornerTopLeft cornerRadii: CGSizeMake(11, 11)];
[rectanglePath closePath];
[UIColor.grayColor setFill];
[rectanglePath fill];

右上角的拐角半径:

UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(x,y,width,height) byRoundingCorners: UIRectCornerTopRight cornerRadii: CGSizeMake(11, 11)];
[rectanglePath closePath];
[UIColor.grayColor setFill];
[rectanglePath fill];

左下边缘的拐角半径:

UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(x,y,width,height) byRoundingCorners: UIRectCornerBottomLeft cornerRadii: CGSizeMake(11, 11)];
[rectanglePath closePath];
[UIColor.grayColor setFill];
[rectanglePath fill];

右下角的拐角半径:

 UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(x,y,width,height) byRoundingCorners: UIRectCornerBottomRight cornerRadii: CGSizeMake(11, 11)];
[rectanglePath closePath];
[UIColor.grayColor setFill];
[rectanglePath fill];

底边的拐角半径:

UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(x,y,width,height) byRoundingCorners: UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii: CGSizeMake(11, 11)];
[rectanglePath closePath];
[UIColor.grayColor setFill];
[rectanglePath fill];

上边缘的拐角半径:

UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(x,y,width,height) byRoundingCorners: UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii: CGSizeMake(11, 11)];
[rectanglePath closePath];
[UIColor.grayColor setFill];
[rectanglePath fill];
           

 类似资料:
  • 问题内容: 在Objective-C中,这样的行 做它的工作,我用类比在Swift中尝试过 并没有任何改变,转角与以前相同。此外,Xcode不会显示任何语法错误。Swift是否支持其他任何方式来实现这一目标?我在这里检查了其他一些线程,通常按上面显示的方式在Swift中完成。 问题答案: 图层从剪辑区域中抽出,您需要将其设置为遮罩边界: 从文档: 默认情况下,拐角半径不适用于图层的contents

  • 我想用圆心(x,y)和半径r画一个圆。

  • 问题内容: 我正在创建路径,并使用和在每个路径中添加多行。然后绘制所有路径。但是某些路径中的线之间有1-2个像素的间隔。如何删除这些空格?我的代码是这样的: 问题答案: 也许这会创造你想要的 :)

  • 问题内容: 我发现只能填充矩形,而没有圆角,该怎么办? 问题答案: HTML5画布没有提供绘制带有圆角的矩形的方法。 如何使用和方法? 您也可以使用方法代替方法。

  • 有没有办法让CardView在顶部只有角半径?

  • 我正在画布上使用二次曲线绘制大型圆角矩形,如下所示: 我可以画一个完整的圆角矩形:http://jsfiddle.net/s9x3xn4z/ 我可以画出圆角矩形的上半部分:http://jsfiddle.net/1oeduLqx/ 但我不知道如何绘制圆角矩形的下半部分。 我的尝试都是这样结束的:http://jsfiddle.net/tfyagcew/ 这绝对不是我想要的! 如何绘制圆角矩形的下半