Skip to content

Commit

Permalink
external border
Browse files Browse the repository at this point in the history
  • Loading branch information
emvakar committed Oct 29, 2022
1 parent e21f58d commit 3d03ada
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Sources/EKTabBarController/EKFloatingBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class EKFloatingBarView: UIView {
super.layoutSubviews()

layer.cornerRadius = cornerRadius
layer.borderColor = borderColor.cgColor
layer.borderWidth = borderWidth
_ = addExternalBorder(borderWidth: borderWidth, borderColor: borderColor)

}

Expand Down
41 changes: 41 additions & 0 deletions Sources/EKTabBarController/UIView+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// UIView+Extension.swift
// EKTabBarController
//
// Created by Emil Karimov on 29.10.2022.
// Copyright © 2022 Emil Karimov. All rights reserved.
//

import UIKit

extension UIView {

struct Constants {
static let ExternalBorderName = "externalBorder"
}

func addExternalBorder(borderWidth: CGFloat = 0, borderColor: UIColor = UIColor.clear) -> CALayer {
let externalBorder = CALayer()
externalBorder.frame = CGRectMake(-borderWidth, -borderWidth, frame.size.width + 2 * borderWidth, frame.size.height + 2 * borderWidth)
externalBorder.borderColor = borderColor.CGColor
externalBorder.borderWidth = borderWidth
externalBorder.name = Constants.ExternalBorderName

layer.insertSublayer(externalBorder, atIndex: 0)
layer.masksToBounds = false

return externalBorder
}

func removeExternalBorders() {
layer.sublayers?.filter() { $0.name == Constants.ExternalBorderName }.forEach() {
$0.removeFromSuperlayer()
}
}

func removeExternalBorder(externalBorder: CALayer) {
guard externalBorder.name == Constants.ExternalBorderName else { return }
externalBorder.removeFromSuperlayer()
}

}

0 comments on commit 3d03ada

Please sign in to comment.