如何在Swift的UIView上应用带有边框的尖角半径?

时间:2018-05-25 14:53:12

标签: swift uiview border layer cornerradius

我想在UIView上设置带有边框的左下角和右下角。这是代码。 **问题是它没有在1.5边框**中显示SHARP

class BorderView: UIView {

  override func draw(_ rect: CGRect) {

    let color = UIColor.red
    let color2 = UIColor.brown

    //// Rectangle Drawing
    let rectanglePath = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: 200, height: 200), byRoundingCorners: [.bottomRight, .bottomLeft], cornerRadii: CGSize(width: 10, height: 10))
    rectanglePath.close()
    color2.setFill()
    rectanglePath.fill()
    color.set()
    rectanglePath.lineWidth = 1.5
    rectanglePath.stroke()

 }
}

OutPut

enter image description here

预期输出

enter image description here

1 个答案:

答案 0 :(得分:1)

如果您使用CALayer上的边框和边角属性,它应该为您完成所有操作。

// Probably inside init
layer.borderWidth = 1.5
layer.borderColor = UIColor.red.cgColor

layer.cornerRadius = 10
layer.maskedCorners = [.layerMinXMaxYCorner, .layerMaxXMaxYCorner]