UIBezierPath和CAShapeLayer没有创建角线

时间:2016-10-28 10:39:24

标签: ios swift cornerradius

这是我的代码

  SELECT DISTINCT lastDisplayName FROM ranks ORDER BY `points` DESC LIMIT 10;

这是我的输出

  

enter image description here

有人可以解释我错在哪里吗?它是关于Swift 3的。

谢谢,

2 个答案:

答案 0 :(得分:1)

嘿,我得到了答案!!!

尝试使用UIBezierPath and CAShapeLayer not creating corner line

var borderShape = CAShapeLayer() 
borderShape.path = round.cgPath
borderShape.lineWidth = 1.0
borderShape.strokeColor = UIColor.blue.cgColor
borderShape.fillColor = nil
borderShape.frame = setMask.bounds
setMask.layer.addSublayer(borderShape)

答案 1 :(得分:0)

更好地使用通用扩展程序:

extension UIView {

func roundedCorners(corners: UIRectCorner, conrnerRadius: CGFloat) {

    let rectShape = CAShapeLayer()
    rectShape.bounds = self.frame

    rectShape.position = self.center
    rectShape.path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: [UIRectCorner.TopLeft , UIRectCorner.TopRight], cornerRadii: CGSizeMake(conrnerRadius, conrnerRadius)).CGPath

    self.layer.mask = rectShape

}
}

调用函数:

 oneextraview.roundedCorners(corners: [UIRectCorner.topRight, UIRectCorner.bottomRight], conrnerRadius: 10.0)
 oneextraview.layer.borderColor = UIColor.redColor().CGColor
 oneextraview.layer.borderWidth = 5.0
 oneextraview.layer.masksToBounds = true
  

注意:在类外的 ViewController 文件或sperate swift文件中声明扩展

output