Round Corners UIView in Swift 4

This solution is working for me to get rounded UIView in Swift 5

view.layer.cornerRadius = 10;
view.clipsToBounds  =  true

I've tried your code and it's working fine with iOS 11.1 & Swift 4.0. (As you have mentioned it shows you an error, but it's not showing me any error)

@IBDesignable
class RoundUIView: UIView {

    @IBInspectable var borderColor: UIColor = UIColor.white {
        didSet {
            self.layer.borderColor = borderColor.cgColor
        }
    }

    @IBInspectable var borderWidth: CGFloat = 2.0 {
        didSet {
            self.layer.borderWidth = borderWidth
        }
    }

    @IBInspectable var cornerRadius: CGFloat = 0.0 {
        didSet {
            self.layer.cornerRadius = cornerRadius
        }
    }

}

Here is result

enter image description here


Update:
Even your updated code is working fine, also.

@IBDesignable
class DesignableView: UIView {
}

extension UIView {

    @IBInspectable
    var cornerRadius: CGFloat {
        get {
            return layer.cornerRadius
        }
        set {
            layer.cornerRadius = newValue
        }
    }
}

Here is result for it:

enter image description here


swift

public func RoundFrameBackground(_ aView: UIView!, borderWidth: CGFloat!, cornerRadius: CGFloat!, borderColor: UIColor, backgroundColor: UIColor) {
    aView.layer.borderWidth = borderWidth ; aView.layer.borderColor = borderColor.cgColor
    aView.backgroundColor = backgroundColor ; aView.clipsToBounds = true
    aView.layer.cornerRadius = cornerRadius
}

public func RoundFrameOnly(_ aView: UIView!, cornerRadius: CGFloat!) {
    aView.clipsToBounds = true
    aView.layer.cornerRadius = cornerRadius
}

use:

RoundFrameBackground(*a view*, borderWidth: 1, cornerRadius: 10, borderColor: UIColor.red, backgroundColor: UIColor.blue)

RoundFrameOnly(*a view*, cornerRadius: 10)