Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rounded corners on iOS 13 page sheet

Tags:

ios

swift

Is there a way to round the corners on an iOS page sheet view controller? Currently, iOS page sheets by default present like this:

unrounded corners on fitted sheet

But instead, I would like the corners to be like this:

rounded corners in page sheet

like image 226
wriuhasdfhvhasdv Avatar asked Oct 31 '25 11:10

wriuhasdfhvhasdv


2 Answers

iOS 15 added an API to customize the corner radius of sheets, UISheetPresentationController.preferredCornerRadius:

let myViewController = UIViewController()
myViewController.view.backgroundColor = .systemYellow
myViewController.sheetPresentationController?.preferredCornerRadius = 25
present(myViewController, animated: true, completion: nil)
like image 119
Jordan H Avatar answered Nov 03 '25 04:11

Jordan H


In your view controller, you can change the view.layer.cornerRadius property to the value you want

override func viewDidLoad() {
    super.viewDidLoad()
    view.layer.cornerRadius = 10.0 // You can freely change this value
}

As an example, the following code:

override func viewDidLoad() {
    super.viewDidLoad()

    view.layer.cornerRadius = 25.0
    view.backgroundColor = .systemPurple
}

gives me the following result:

cornerRadiusExample

like image 42
tomrcht Avatar answered Nov 03 '25 03:11

tomrcht



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!