Search code examples
uiviewuikitswift4ios11xcode9

Adding a inner border bottom to a subclass of UiView in swift4


I want to add an inner border bottom to one of the subclass(custom) of UIView , I am looking if there is an extension for the UIview . Thanks in advance.


Solution

  • extension UIView {
        func customBorder(){
            let borderWidth: CGFloat = 0.84
            self.frame = frame.insetBy(dx: -borderWidth, dy: -borderWidth)
            self.layer.borderColor = UIColor.white.cgColor
            self.layer.borderWidth = borderWidth
            self.clipsToBounds = true
        }
    }