UIView: how to rounded borders of subview in view?

22 views Asked by At

I would like to get this result:

enter image description here

I tried this in my view controller:

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)
}

But I'm getting this result:

enter image description here

How can I achieve this result?

Thank you for your help

1

There are 1 answers

0
SachinVsSachin On BEST ANSWER

Try this code, as here you need to set super view clip to bound property true, not to it's subview.

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)
}