How can i present viewController in modal. am a new beginner in ios and am using swift4 I try this
let userVC = mainStoryboard.instantiateViewController(withIdentifier:
"menuC") as! MenuController
userVC.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
userVC.navigationController?.modalPresentationStyle =
UIModalPresentationStyle.overCurrentContext
present(userVC, animated: true, completion: nil)
To create a new view controller, select File->New->File and select a Cocoa Touch Class. Choose whether to create it with Swift or Objective-C and inherit from UIViewController . Don't create it with a xib (a separate Interface Builder file), as you will most likely add it to an existing storyboard.
Do like this
if let presentedViewController = self.storyboard?.instantiateViewController(withIdentifier: "menuC") {
presentedViewController.providesPresentationContextTransitionStyle = true
presentedViewController.definesPresentationContext = true
presentedViewController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext;
presentedViewController.view.backgroundColor = UIColor.init(white: 0.4, alpha: 0.8)
self.present(presentedViewController, 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