gpt4 book ai didi

ios - UIButton 向左拐角时消失

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

我只想将按钮的左下角圆角化,但当我实现以下代码时,该按钮会从 View 中消失。

代码

    cancelBtn.setTitle("Cancel", for: .normal)
cancelBtn.setTitleColor(UIColor.ecaftRed, for: .normal)
cancelBtn.layer.borderWidth = 3
cancelBtn.layer.borderColor = UIColor.whiteFadedPlus.cgColor
cancelBtn.roundBtnCorners([.bottomLeft], radius: 25)
cancelBtn.addTarget(self, action: #selector(cancelBtnTapped(_:)), for: .touchUpInside)
popUpView.addSubview(cancelBtn)

cancelBtn.snp.makeConstraints { (make) -> Void in
make.left.equalTo(popUpView)
make.bottom.equalTo(popUpView)
make.size.equalTo(CGSize(width: 0.5*popUpView.frame.width, height: 0.25*popUpView.frame.height))
}


extension UIButton{

func roundBtnCorners(_ corners:UIRectCorner, radius: CGFloat){
let path = UIBezierPath(roundedRect: self.bounds,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius, height: radius))
let maskLayer = CAShapeLayer()
maskLayer.frame = self.bounds
maskLayer.path = path.cgPath
self.layer.mask = maskLayer
}
}

Source

最佳答案

按钮的范围很可能为零或接近于零。因此按钮不会显示,或者 mask 将遮盖整个内容。

关于ios - UIButton 向左拐角时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48486894/

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