gpt4 book ai didi

ios - UIButton 的圆形左边框

转载 作者:行者123 更新时间:2023-11-28 07:55:06 30 4
gpt4 key购买 nike

为了使 UIButton 的左下角变圆,我取了 code from this answer并修改了行:borderLayer.strokeColor = GenerateShape.UIColorFromHex(0x989898, alpha: (1.0-0.3)).CGColor b/c 它不起作用。

但是,UIButton 的左边框不是圆角的。如何修复?

enter image description here

代码

    button.frame = CGRect(x: 0, y: 0, width: 0.5*popUpView.frame.width, height: 0.25*popUpView.frame.height)
button.layer.borderWidth = 3
button.roundBtnCorners(roundedCorners, radius: cornerRadius)

extension UIButton{
// Round specified corners of button
func roundBtnCorners(_ corners:UIRectCorner, radius: CGFloat)
{
let borderLayer = CAShapeLayer()
borderLayer.frame = self.layer.bounds
borderLayer.strokeColor = UIColor(red: 168/266, green: 20/255, blue: 20/255, alpha: 0.7).cgColor
borderLayer.fillColor = UIColor.clear.cgColor
borderLayer.lineWidth = 1.0
let path = UIBezierPath(roundedRect: self.bounds,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius, height: radius))
borderLayer.path = path.cgPath
self.layer.addSublayer(borderLayer);
}
}

最佳答案

代替:

self.layer.addSublayer(borderLayer)

尝试:

self.layer.mask = borderLayer

关于ios - UIButton 的圆形左边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48488540/

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