Skip to content

Commit

Permalink
Merge pull request #150 from seanwoodward/BorderFix
Browse files Browse the repository at this point in the history
fix to allow single sided borders
  • Loading branch information
JakeLin committed Apr 3, 2016
2 parents ff35675 + 1bf1502 commit f8a9b68
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions IBAnimatable/BorderDesignable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,23 @@ public protocol BorderDesignable {

public extension BorderDesignable where Self: UIView {
public func configBorder() {
func clearBorders() {
layer.sublayers?.filter { $0.name == "borderSideLayer" || $0.name == "borderAllSides" }
.forEach { $0.removeFromSuperlayer() }
}

guard let unwrappedBorderColor = borderColor else {
clearBorders()
return
}

if borderWidth.isNaN || borderWidth <= 0 {
clearBorders()
return
}

layer.sublayers?.filter { $0.name == "borderSideLayer" }
.forEach { $0.removeFromSuperlayer() }
clearBorders()

if let unwrappedBorderSide = borderSide, side = BorderSide(rawValue: unwrappedBorderSide) {
configBorderWithSide(side, borderColor: unwrappedBorderColor)
} else {
Expand Down Expand Up @@ -63,6 +70,7 @@ public extension BorderDesignable where Self: UIView {
private func configBorderForAllSides(borderColor: UIColor) {
if let mask = layer.mask as? CAShapeLayer {
let borderLayer = CAShapeLayer()
borderLayer.name = "borderAllSides"
borderLayer.path = mask.path
borderLayer.fillColor = UIColor.clearColor().CGColor
borderLayer.strokeColor = borderColor.CGColor
Expand Down

0 comments on commit f8a9b68

Please sign in to comment.