HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – UIBezierPath:roundedRect:byRoundingCorners:cornerRadii:行为怪异大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图让一个按钮的两个角圆.如果我像这样选择.TopLeft和.bottomLeft:

let bezierDisableAdsPath = UIBezierPath(roundedRect: disableAdsButton.bounds,byRoundingCorners: [UIRectCorner.TopLeft,UIRectCorner.bottomLeft],cornerRadii: CGSizeMake(4.0,4.0))

        let maskAdsLayer = CAShapeLayer()
        maskAdsLayer.frame = disableAdsButton.bounds
        maskAdsLayer.path = bezierDisableAdsPath.CGPath
        disableAdsButton.layer.mask = maskAdsLayer

代码工作得很漂亮.

如果我选择.TopRight和. BottomRight是这样的

let bezierDisableAdsPath = UIBezierPath(roundedRect: disableAdsButton.bounds,byRoundingCorners: [UIRectCorner.TopRight,UIRectCorner.bottomRight],4.0))

        let maskAdsLayer = CAShapeLayer()
        maskAdsLayer.frame = disableAdsButton.bounds
        maskAdsLayer.path = bezierDisableAdsPath.CGPath
        disableAdsButton.layer.mask = maskAdsLayer

比我看不到圆角.这里发生了什么?

我已经尝试将maskAdsLayer添加为子视图,但它不起作用.

解决方法

如果您在viewDidLoad中执行此操作,此时可能尚未应用自动布局约束,因此按钮的框架可能未达到其最终值,因此disableAdsButton.bounds可能不是您所期望的那样在那时候.因此,向右倒圆的角可能不可见.您可以通过在此代码运行的位置记录按钮的边界来确认这一点,然后在布局视图后再次查看它.

你可以通过推迟到viewDidAppear或更好的viewDidLayoutSubviews来解决这个问题.

大佬总结

以上是大佬教程为你收集整理的ios – UIBezierPath:roundedRect:byRoundingCorners:cornerRadii:行为怪异全部内容,希望文章能够帮你解决ios – UIBezierPath:roundedRect:byRoundingCorners:cornerRadii:行为怪异所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。