I am trying to present a custom view from a controller modally, however when I do so the background of everything but the textfield I have turns black as seen in here . (the intended modal)
This seems to be a fairly common problem, however I have already implemented the code that most similar questions pose as the answer
here is my addEvent method in the first controller:
@IBAction func addEvent(_ sender: Any) {
let newEventViewController = NewEventViewController()
newEventViewController.view.backgroundColor = UIColor.clear
newEventViewController.view.isOpaque = false
navigationController?.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
navigationController?.present(newEventViewController, animated: true, completion: nil)
}
Any help figuring out what I am missing would be appreciated. If it makes a difference I am creating my app using individual xib files and not a storyboard.
You need to set the modalPresentationStyle of newEventController not the navigationController like this:
newEventViewController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
Also although not needed I would present from self rather than the navigation controller like this:
self.present(newEventViewController, animated: true, completion: nil)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With