Computer >> Computer tutorials >  >> Programming >> IOS

How to create transparent Status Bar and Navigation Bar in iOS?


You might have come across many application where the screen extends to complete screen i.e transparent Status Bar and transparent navigation bar.

Here we will be seeing how to create an application where the you’ll be having transparent status and navigation bar.

So let’s get started

Step 1 − Open Xcode → New Project → Single View Application → Let’s name it “TransparentViews”

Step 2 − Embed the View Controller in Navigation Controller. Add Image View and shown and add image.

How to create transparent Status Bar and Navigation Bar in iOS?

Step 3 − Run the application without adding any piece of code for making status and navigation bar transparent.

The screen looks like below

How to create transparent Status Bar and Navigation Bar in iOS?

Step 4 − Now Open ViewController.swift and add following code in viewDidLoad method.

override func viewDidLoad(){
   super.viewDidLoad()
   self.navigationController!.navigationBar.setBackgroundImage(UIImage(), for: .default)
   self.navigationController!.navigationBar.shadowImage = UIImage()
   self.navigationController!.navigationBar.isTranslucent = true
}

Step 5 − Run the application

How to create transparent Status Bar and Navigation Bar in iOS?