带角和隐藏底部边框的按钮
button with corner and hide bottom border
我想要的结果
我得到了什么:
我使用这个代码:
func roundedTopLeftButton(radius : Int, colorBorder : UIColor) {
// Add border
let gradient = CAGradientLayer()
let size = CGSize(width: self.frame.width, height: self.frame.height)
let rect = CGRect(origin: .zero, size: size)
gradient.frame = CGRect(origin: CGPoint.zero, size: size)
gradient.colors = [UIColor.blue.cgColor, UIColor.green.cgColor]
let shape = CAShapeLayer()
shape.lineWidth = 2
shape.path = UIBezierPath(roundedRect: rect,
byRoundingCorners: [.topLeft , .topRight],
cornerRadii: CGSize(width: radius, height: radius)).cgPath
shape.strokeColor = colorBorder.cgColor
shape.fillColor = UIColor.clear.cgColor
gradient.mask = shape
self.layer.addSublayer(shape)
}
请问如何隐藏付款按钮的按钮边框?
使用自定义路径,Corner Radius没有什么复杂的。
你只需要在纸上画出你的形状 sheet。标记兴趣点,了解一点三角学(只是了解角度)和一点基本几何。
let path = UIBezierPath()
path.move(to: CGPoint(x: 0, y: bounds.size.height))
path.addLine(to: CGPoint(x: 0, y: radius))
path.addArc(withCenter: CGPoint(x: radius, y: radius),
radius: radius,
startAngle: CGFloat.pi,
endAngle: -CGFloat.pi/2.0,
clockwise: true)
path.addLine(to: CGPoint(x: bounds.size.width - radius, y: 0))
path.addArc(withCenter: CGPoint(x: bounds.width - radius, y: radius),
radius: radius,
startAngle: -CGFloat.pi/2.0,
endAngle: 0,
clockwise: true)
path.addLine(to: CGPoint(x: bounds.size.width, y: bounds.size.height))
我想要的结果
我得到了什么:
我使用这个代码:
func roundedTopLeftButton(radius : Int, colorBorder : UIColor) {
// Add border
let gradient = CAGradientLayer()
let size = CGSize(width: self.frame.width, height: self.frame.height)
let rect = CGRect(origin: .zero, size: size)
gradient.frame = CGRect(origin: CGPoint.zero, size: size)
gradient.colors = [UIColor.blue.cgColor, UIColor.green.cgColor]
let shape = CAShapeLayer()
shape.lineWidth = 2
shape.path = UIBezierPath(roundedRect: rect,
byRoundingCorners: [.topLeft , .topRight],
cornerRadii: CGSize(width: radius, height: radius)).cgPath
shape.strokeColor = colorBorder.cgColor
shape.fillColor = UIColor.clear.cgColor
gradient.mask = shape
self.layer.addSublayer(shape)
}
请问如何隐藏付款按钮的按钮边框?
使用自定义路径,Corner Radius没有什么复杂的。 你只需要在纸上画出你的形状 sheet。标记兴趣点,了解一点三角学(只是了解角度)和一点基本几何。
let path = UIBezierPath()
path.move(to: CGPoint(x: 0, y: bounds.size.height))
path.addLine(to: CGPoint(x: 0, y: radius))
path.addArc(withCenter: CGPoint(x: radius, y: radius),
radius: radius,
startAngle: CGFloat.pi,
endAngle: -CGFloat.pi/2.0,
clockwise: true)
path.addLine(to: CGPoint(x: bounds.size.width - radius, y: 0))
path.addArc(withCenter: CGPoint(x: bounds.width - radius, y: radius),
radius: radius,
startAngle: -CGFloat.pi/2.0,
endAngle: 0,
clockwise: true)
path.addLine(to: CGPoint(x: bounds.size.width, y: bounds.size.height))