Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to present a view controller with smaller size

I want presented view controller vc2 in smaller size than the screen, how to do that in Swift 3 ?? Thanks for help. This is my code:

@IBAction func leftButtonPressed(_ sender: UIButton) {
    let vc2 = self.storyboard?.instantiateViewController(withIdentifier: "Controller2") as! ViewController2
    vc2.modalPresentationStyle = .currentContext

    present(vc2, animated: true, completion: nil)
}
like image 460
Peterq2001 Avatar asked Jun 20 '17 21:06

Peterq2001


1 Answers

Try this..

@IBAction func leftButtonPressed(_ sender: UIButton) {
    let vc2 = self.storyboard?.instantiateViewController(withIdentifier: "Controller2") as! ViewController
    vc2.providesPresentationContextTransitionStyle = true
    vc2.definesPresentationContext = true
    vc2.modalPresentationStyle=UIModalPresentationStyle.overCurrentContext
    self.present(vc2, animated: true, completion: nil)

    // Make sure your vc2 background color is transparent
    vc2.view.backgroundColor = UIColor.clear
}
like image 177
Bilal Avatar answered Nov 09 '22 09:11

Bilal