Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to present ViewController in modaly swift 4

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)
like image 370
wizmea Avatar asked Dec 22 '17 04:12

wizmea


People also ask

How do I add a ViewController to a storyboard?

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.


1 Answers

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)
    }
like image 143
wizmea Avatar answered Oct 28 '22 17:10

wizmea