JoanKing / JKSwiftExtension

Swift常用扩展、组件、协议,方便项目快速搭建,提供完整清晰的Demo示例,不断的完善中......
Apache License 2.0
761 stars 122 forks source link

UIView+Extension中5.2、添加圆角和边框 方法addCorner 有问题 #37

Closed Zss1990 closed 1 year ago

Zss1990 commented 1 year ago

库很棒,给作者点赞!👍🏻 在使用中发现 UIView+Extension中5.2、添加圆角和边框 方法: // MARK: 5.2、添加圆角和边框
/// 添加圆角和边框 /// - Parameters: /// - conrners: 具体哪个圆角 /// - radius: 圆角的大小 /// - borderWidth: 边框的宽度 /// - borderColor: 边框的颜色 func addCorner(conrners: UIRectCorner , radius: CGFloat, borderWidth: CGFloat, borderColor: UIColor) { let maskPath = UIBezierPath(roundedRect: self.base.bounds, byRoundingCorners: conrners, cornerRadii: CGSize(width: radius, height: radius)) let maskLayer = CAShapeLayer() maskLayer.frame = self.base.bounds maskLayer.path = maskPath.cgPath self.base.layer.mask = maskLayer

    // Add border
    let borderLayer = CAShapeLayer()
    borderLayer.path = maskLayer.path
    borderLayer.fillColor = UIColor.clear.cgColor
    borderLayer.strokeColor = borderColor.cgColor
    borderLayer.lineWidth = borderWidth
    borderLayer.frame =  self.base.bounds
    self.base.layer.addSublayer(borderLayer)
}

存在图层报错问题,borderLayer这里设置是否有问题?请大佬帮忙看下

JoanKing commented 1 year ago

代码没问题的,您这边是怎么使用的?方便的话我加您个微信或者您加我(wangc2318151015)

JoanKing commented 1 year ago

暂时没复现