UIBezierPath doesn't work in TopRight corner and BottomRight corner

三世轮回 提交于 2019-11-27 14:26:52

The problem is that you're getting the view's bounds before it's been resized for the current device. It's larger than it will be later when it appears on screen, so the right side of your rounded rect is off the right side of the screen.

You need to create path and set maskLayer.path later, after the view has been resized, which means during or after the layout phase of the run loop. So either subclass the view and do it in the view's layoutSubviews method, or do it in the view controller's viewDidLayoutSubviews method.

matt

Swift 3

It works for me !

override func layoutSubviews() {
    super.layoutSubviews()
    DispatchQueue.main.async {
       self.containerView.roundCorners(corners: [.topRight,.topLeft], radius: 25)
       self.containerView.layer.masksToBounds = true
    }
    self.layoutIfNeeded()
}

You can check the method "roundCorners" here : https://stackoverflow.com/a/41217863/3687902

Kiran K

If you are tried to set the RoundingCorners for View which are design on Storyboard OR Xib then please set the corner and MaskLayer.path into below method.

override func viewDidLayoutSubviews() {
// here you can write the code...
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!