Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Present ViewController with Transparent Background in Swift iOS App - Basic Steps

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3
    • 0
    • 9.91k
    Comment on it

    Sometimes we have to show a transparent View on a ViewController, For that we generally use .xib file and add them as subView in ViewController to show the transparency. But we can also give the transparency to view controller while presenting this.

     

     

    So here are the basic steps you need to follow to present a ViewController with transparent background

    1- Create a new project.
    2- You will see a already created ViewController on the story board.
    3- Add another ViewController that you want to present(i.e PresentViewController).
    4- set the background color of PresentViewController with some alpha.
    5- Create a segue from ViewController to PresentViewController.
    6- Set the segue kind to Present Modally in storyBoard also give a identifier to segue something like this - “transparentSegueId” .
    7- Add a button on the ViewController To present the Transparent ViewController.
    8-  Create an action for this button in ViewController class.

    @IBAction func presnetMyVC(){
            performSegue(withIdentifier: "transparentSegueId", sender: nil)
        }
    


    Add another method for handling the segue.
     

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
            if segue.identifier == "transparentSegueId"{
                let destinationVC = segue.destination
                destinationVC.modalPresentationStyle = .overCurrentContext
            }
        }

    Output-> Screen 1 ViewController from we presenting the another viewController.



    Screen 2 - Controller we are presenting with transparency

    Present ViewController with Transparent Background in Swift iOS App - Basic Steps

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: