在swift4中向UiView的子类添加内边框底部

在swift4中向UiView的子类添加内边框底部,uiview,uikit,swift4,ios11,xcode9,Uiview,Uikit,Swift4,Ios11,Xcode9,我想在UIView的一个子类(custom)中添加一个内边框底部,我正在查看UIView是否有扩展。提前感谢。swift4中的CGRect.insetBy方法取代了CGRect INSET。怎么办?@kamalakshihegde检查更新的答案。您还可以将目标C代码转换为swift extension UIView { func customBorder(){ let borderWidth: CGFloat = 0.84 self.frame = fra

我想在UIView的一个子类(custom)中添加一个内边框底部,我正在查看UIView是否有扩展。提前感谢。

swift4中的CGRect.insetBy方法取代了CGRect INSET。怎么办?@kamalakshihegde检查更新的答案。您还可以将目标C代码转换为swift
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
    }
}