UIView:如何在视图中圆角子视图的边框?

UIView: how to rounded borders of subview in view?

我想得到这个结果:

我在我的视图控制器中试过这个:

override func viewDidLoad() {
    roundView.layer.cornerRadius = 10.0
    let blueView = UIView(frame: CGRect(origin: .zero,
                                        size: CGSize(width: 5, height: roundView.bounds.height)))
    blueView.backgroundColor = .blue
    blueView.clipsToBounds = true
    roundView.addSubview(blueView)
}

但我得到了这个结果:

我怎样才能达到这个结果?

感谢您的帮助

试试这个代码,因为这里你需要将超级视图剪辑设置为绑定 属性 true,而不是它的子视图。

override func viewDidLoad() {
    roundView.layer.cornerRadius = 10.0
    roundView.clipsToBounds = true
    let blueView = UIView(frame: CGRect(origin: .zero,
                                        size: CGSize(width: 5, height: roundView.bounds.height)))
    blueView.backgroundColor = .blue
    roundView.addSubview(blueView)
}