ios – 如何设置仅在UIView的左下角,右下角和左上角的cornerRadius?

ios – 如何设置仅在UIView的左下角,右下角和左上角的cornerRadius?,第1张

概述有没有办法只设置一个UIView的左下角右下角左上角的cornerRadius? 我试过以下,但最终使视图消失。下面的代码有什么问题吗? UIBezierPath *maskPath; maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:(UIRectCornerBottomL 有没有办法只设置一个UIVIEw的左下角,右下角和左上角的cornerRadius?

我试过以下,但最终使视图消失。下面的代码有什么问题吗?

UIBezIErPath *maskPath;    maskPath = [UIBezIErPath bezIErPathWithRoundedRect:vIEw.bounds byRoundingCorners:(UIRectCornerBottomleft | UIRectCornerBottomright) cornerRadii:CGSizeMake(20.0,20.0)];    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];    maskLayer.path = maskPath.CGPath;    vIEw.layer.mask = maskLayer;
解决方法 你可以这样做:

UIBezIErPath *maskPath = [UIBezIErPath bezIErPathWithRoundedRect:self.vIEwOutlet.bounds byRoundingCorners:(UIRectCornertopleft | UIRectCornerBottomleft | UIRectCornerBottomright) cornerRadii:CGSizeMake(10.0,10.0)];CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];maskLayer.frame = self.vIEw.bounds;maskLayer.path  = maskPath.CGPath;self.vIEwOutlet.layer.mask = maskLayer;

更新:
如果您需要边框,只需创建另一个CAShapeLayer,并将其添加到视图层作为子图层。像这样(将此代码放在下面的代码下面):

CAShapeLayer *borderLayer = [[CAShapeLayer alloc] init];borderLayer.frame = self.vIEw.bounds;borderLayer.path  = maskPath.CGPath;borderLayer.linewidth   = 4.0f;borderLayer.strokecolor = [UIcolor blackcolor].CGcolor;borderLayer.fillcolor   = [UIcolor clearcolor].CGcolor;[self.vIEwOutlet.layer addSublayer:borderLayer];
总结

以上是内存溢出为你收集整理的ios – 如何设置仅在UIView的左下角,右下角和左上角的cornerRadius?全部内容,希望文章能够帮你解决ios – 如何设置仅在UIView的左下角,右下角和左上角的cornerRadius?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1087041.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存