[英]Round left border of a UIButton
To round the bottom left corner of a UIButton
, I took code from this answer and modified the line: borderLayer.strokeColor = GenerateShape.UIColorFromHex(0x989898, alpha: (1.0-0.3)).CGColor
b/c it didn't work. 为了绕过
UIButton
左下角,我从该答案中获取了代码并修改了以下代码 : borderLayer.strokeColor = GenerateShape.UIColorFromHex(0x989898, alpha: (1.0-0.3)).CGColor
b / c无效。
However, the left border of the UIButton
is not rounded. 但是,
UIButton
的左边框未舍入。 How to fix? 怎么修?
Code 码
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);
}
}
Istead of: 代替:
self.layer.addSublayer(borderLayer)
Try: 尝试:
self.layer.mask = borderLayer
I cannot see how you are creating the parameters for roundBtnCorners but below is the line I changed in your code and it worked. 我看不到您如何为roundBtnCorners创建参数,但是下面是我在代码中更改的行,它可以正常工作。 I would check to make sure you are passing the correct parameters.
我将检查以确保您传递正确的参数。
button.roundBtnCorners(.bottomLeft , radius: 10)
Solved it! 解决了! It was because my
button.layer.borderWidth = 3
was drawing a really thick rectangle, so I couldn't see the border drawn by roundBtnCorners
这是因为我的
button.layer.borderWidth = 3
正在绘制一个非常粗的矩形,所以我看不到roundBtnCorners
绘制的roundBtnCorners
I deleted the line below: 我删除了下面的行:
button.layer.borderWidth = 3
Result: 结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.