【问题标题】:UIView: how to rounded borders of subview in view?UIView:如何在视图中圆角子视图的边框?
【发布时间】:2021-04-20 18:43:57
【问题描述】:

我想得到这个结果:

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

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

但我得到了这个结果:

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

感谢您的帮助

【问题讨论】:

    标签: ios uiview uikit round-corner


    【解决方案1】:

    试试这个代码,因为这里你需要将超级视图剪辑设置为绑定属性 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)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-12-23
      • 2021-03-16
      • 1970-01-01
      • 2022-12-29
      • 1970-01-01
      • 2019-11-24
      相关资源
      最近更新 更多