gpt4 book ai didi

ios - 如何只为 topLeft 和 bottomLeft 角设置圆角?

转载 作者:行者123 更新时间:2023-11-28 10:58:02 24 4
gpt4 key购买 nike

我关注了其他 stackoverflow 线程并创建了 CAShapeLayer 并将其添加到按钮层。

let bazierPath = UIBezierPath.init(roundedRect: button.bounds, byRoundingCorners: [UIRectCorner.bottomLeft, UIRectCorner.topLeft], cornerRadii: CGSize(width: 10.0, height: 10.0 ))
let shapeLayer = CAShapeLayer()
shapeLayer.frame = button.bounds
shapeLayer.path = bazierPath.cgPath
shapeLayer.strokeColor = UIColor.green.cgColor
shapeLayer.lineWidth = 1.0
button.layer.mask = shapeLayer

但问题是我得到了颜色清晰的角,但我希望它们是绿色的。检查下图中带有“Mon”和“Fri”的按钮,以便清楚地了解问题。

enter image description here

最佳答案

在您的代码中,您忘记将 addSublayer 添加到主层 contentView.layer.addSublayer(subLayer) 以用于示例目的

  let contentView = UIView(frame: CGRect(x: CGFloat(50), y: CGFloat(100), width: CGFloat(200), height: CGFloat(100)))
self.view.addSubview(contentView)
let subLayer = CAShapeLayer()
subLayer.fillColor = UIColor.blue.cgColor
subLayer.strokeColor = UIColor.green.cgColor
subLayer.lineWidth = 1.0
subLayer.path = UIBezierPath(roundedRect: contentView.bounds, byRoundingCorners: [UIRectCorner.bottomLeft, UIRectCorner.topLeft], cornerRadii: CGSize(width: 10.0, height: 10.0 )).cgPath
contentView.layer.addSublayer(subLayer)

输出

enter image description here

关于ios - 如何只为 topLeft 和 bottomLeft 角设置圆角?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42084262/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com