Change cornerRadius of the modal view controller

Viewed 2054

My goal is to increase corner radius of the modally presented controller to 25. As you can see in the picture it has rounded corners by default but I need them to have greater radius. I've tried rounding corners by accessing controllers view, but it's not working.

view.layer.cornerRadius = 25

I haven't found any mention of it in the apple documentation, is there any way to make it work? Is this even possible?

enter image description here

3 Answers

You can get the effect by changing your presented view controller's top view's background to clear which hides the view where the presenter is rounding corners. Then just round the corners of the next top view to the desired amount.

you can't, that's a custom presentation controller created by apple that is a protected/private API to conform to new design standards throughout the apple eco system for ios 13 and beyond. what you can do instead is create your own subclass implementation of UIPresentationController and then round the corners to whatever corner radius you wish. subclassing UIPresentationController with pan gestures that interact well with even first degree nesting of scroll views is a daunting task, however. I'd check out some example code for this before you try to override the default since doing so will land you in a black hole of chaos pretty quickly unless you're well versed in UIKit, Foundation, and delegation with ios.

I see, that it's probably too late for you, but maybe it will be useful to others. I used layer(gradient) with mask, but I think, you can modify it as you like

    self.view.backgroundColor = .clear
    let mask = CAShapeLayer()

    mask.path = UIBezierPath(roundedRect: tableView.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize.init(width: 25, height: 25)).cgPath

    // You can use with layer of viewConroller's view
    self.view.layer.backgroundColor = UIColor.green.cgColor
    self.view.layer.mask = mask

    // And gradient background for VC
    let gradient = CAGradientLayer()
    gradient.colors = [UIColor.green.cgColor, UIColor.blue.cgColor]
    gradient.frame = view.bounds
    gradient.mask = mask
    self.view.layer.insertSublayer(gradient, at: 0)


    
Related