首页 > 编程语言 >ios - 如何使用 CAShaperLayer 设置圆角半径值?

ios - 如何使用 CAShaperLayer 设置圆角半径值?

时间:2023-02-22 10:25:54浏览次数:47  
标签:pathLayer 圆角 CAShapeLayer CGPointMake ios layer CAShaperLayer path spaceBetweenB

https://www.coder.work/article/785950

 

我用 UIBeizerPath 画了一条垂直线,我需要这条线的角半径值为 5。我试图记忆起 [pathLayer setCornerRadius: 5]; 但我没有得到结果... 你能帮助我吗?如何分配角半径值?这是我使用的代码

    // crea le barre del grafico e gli assegna l'altezza della label y corrispondente
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(xPaddingFromYAxis +spaceBetweenBar *j, 200)];
    [path addLineToPoint:CGPointMake(xPaddingFromYAxis +spaceBetweenBar *j,  yLabelValue.center.y )];

    CAShapeLayer *pathLayer = [CAShapeLayer layer];
    pathLayer.frame = self.bounds;
    pathLayer.path = path.CGPath;
    pathLayer.strokeColor = [UIColor darkGrayColor].CGColor;
    pathLayer.fillColor = nil;
    pathLayer.lineWidth = 50;
    [pathLayer setCornerRadius:5];
    pathLayer.masksToBounds = NO;
    [scroll.layer addSublayer:pathLayer];

enter image description here

 

最佳答案

 

您需要将掩码绑定(bind)设置为"is"。 pathLayer.masksToBounds = YES;


试试看:

UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(xPaddingFromYAxis +spaceBetweenBar *j, 200)];
[path addLineToPoint:CGPointMake(xPaddingFromYAxis +spaceBetweenBar *j,  yLabelValue.center.y )];

CAShapeLayer *pathLayer = [CAShapeLayer layer];
pathLayer.frame = self.bounds;
pathLayer.path = path.CGPath;
pathLayer.strokeColor = [UIColor darkGrayColor].CGColor;
pathLayer.fillColor = nil;
pathLayer.lineWidth = 50;
[pathLayer setCornerRadius:5];
pathLayer.masksToBounds = YES;
[scroll.layer addSublayer:pathLayer];

 

关于ios - 如何使用 CAShaperLayer 设置圆角半径值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46565095/

标签:pathLayer,圆角,CAShapeLayer,CGPointMake,ios,layer,CAShaperLayer,path,spaceBetweenB
From: https://www.cnblogs.com/itlover2013/p/17143379.html

相关文章

  • iOS Swift开发中JSON对象/JSON字符串/Data的互转
    https://www.jianshu.com/p/712bb9a60184 JSON(对象)----->JSON字符串//JSON--->data--->JSON字符串letdata=try?JSONSerialization.data(withJSONObject:json......
  • iOS使用swift开发SDK遇到的版本冲突问题
    https://www.jianshu.com/p/bbe0951f1b0b 如果你用Swift开发SDK,你大概会收到类似这样的编译问题ModulecompiledwithSwift5.3.2cannotbeimportedbytheSwift......
  • [OS] 这系统只为游戏而生 ReviOS游戏定制版 Win11/Win10
    [OS]这系统只为游戏而生ReviOS游戏定制版Win11/Win10此文章引用地址:https://www.hybase.com/xitong/windows/2679.html哈喽,黑域小伙伴,针对游戏玩家而定制的系统版本......
  • iOS APP开发经验分享!
    一、学习iOS了解iOS的基本规范和设计准则,了解现在市场上主流的几款iPhone手机尺寸以及分辨率,弄清楚不同版本iPhone物理像素(pt)和逻辑像素(px)的关系了解不同尺寸屏幕的适配......
  • 关于WPF的圆角
    失败案例<BorderCornerRadius="3"Width="100"Height="100"><StackPanelBackground="Red"></StackPanel></Border>换成下面就成功?为什么?<BorderCornerRa......
  • ios中safari浏览器中window.open()无效的问题
    safari浏览器为了避免弹出广告影响用户,禁用了通过代码调用超链接在新标签打开页面的功能。所以在接口返回中调用window.open()打开链接无效。解决方法:接口返回中,把window.......
  • 2022社交平台设备风险安卓占三成,iOS 仅占一成
    随着移动互联网的发展,社交媒体进入“人人皆媒”时代。社交不再仅仅满足于用户即时通讯的需求,还承载了在线支付、内容分享等等的多元功能,正不断刷新着用户日常沟通、购物和......
  • iOS FileManager使用
    https://www.jianshu.com/p/39b7093fb862 在iOS应用开发的过程中,很多时候要用到数据存储,将数据存储在磁盘中。FileManager在存储的过程中就起到非常重要的作用,文件的......
  • Vue3集成axios分环境调用
    版本node16.18.0Vue3配置基础环境安装axiosnpminstallaxios编写dev与prod环境文件devNODE_ENV='development'prodNODE_ENV='production'动......
  • 在项目中用ts封装axios,一次封装整个团队受益
    虽然说FetchAPI已经使用率已经非常的高了,但是在一些老的浏览器还是不支持的,而且axios仍然每周都保持2000多万的下载量,这就说明了axios仍然存在不可撼动的地位,接下来我......