【问题标题】:button with corner and hide bottom border带角的按钮并隐藏底部边框
【发布时间】:2020-05-29 10:21:13
【问题描述】:

我想要的结果

我得到了什么:

我使用这个代码:

    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)
}

请问如何隐藏按钮Paiements的按钮边框?

【问题讨论】:

  • 你需要画这条路
  • 我怎么画?
  • 我不是 bezierPath 专家 :)

标签: swift xcode border uibezierpath


【解决方案1】:

使用自定义路径,拐角半径没有什么复杂的。 你只需要在一张纸上画出你的形状。标记兴趣点,了解一点三角学(这只是了解角度)和一点基本几何学。

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))

【讨论】:

  • 什么是半径?
猜你喜欢
  • 2018-01-14
  • 1970-01-01
  • 2021-05-07
  • 2014-12-16
  • 2016-10-26
  • 1970-01-01
  • 1970-01-01
  • 2020-08-29
  • 2018-05-07
相关资源
最近更新 更多