maksonnie
maksonnie

Reputation: 743

How to hide view's shadow after its presenting?

I want to call a UIView with transparent background from table cell.

let myView = MyViewController()
myView.view.backgroundColor = .clear
tableController.present(myView, animated: true, completion: nil)

But there remains such an unpleasant border. enter image description here

myView.modalPresentationStyle = .fullScreen makes it worse - remove background view.

Upvotes: 0

Views: 1139

Answers (2)

Declan Land
Declan Land

Reputation: 650

Important to note, if you're using a .xib, viewDidLoad isn't the correct place to place your modalPresentationStyle change. This should be done before the view is loaded.

Upvotes: 0

Raman Shyniauski
Raman Shyniauski

Reputation: 422

You can present new viewController in a .fullscreen (or any other) mode with transparent background

  1. Add view with content inside viewController
  2. Add custom background color to the main viewController's view. Set opacity to any value less than 100% (e.g. 30% - see screen below)
  3. Change viewController's presentation style to .overCurrentContext

Here is how you can do that programmatically

//apply that for viewController that will be displayed at the top
viewController.modalPresentationStyle = .fullScreen
viewController.modalPresentationStyle = .overCurrentContext

enter image description here

Upvotes: 1

Related Questions