Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 8.2: Swift3- how to hide status bar?

Tags:

xcode

ios

swift

all trying to hide status bar with Xcode 8.2 with swift 3. but I can't hide it.

enter image description here

enter image description here

and also for,

enter image description here

like image 791
john afordis Avatar asked Dec 21 '16 05:12

john afordis


People also ask

How do I hide status bar in SwiftUI?

Make sure your initial SwiftUI View is a Navigation view where you hide the status bar. Then if you navigate to a tab bar view or any subsequent views the status bar will be hidden.

How do I change the color of a status bar in Swift?

If you are using Storyboard , go to the NavigationController , select the navigationBar , click on the Attributes Inspector , then change the style . if you need light content (white status bar) set it anything except default lets say set style black And if you want dark content (black status bar) set it default .


2 Answers

You can Approach this in two ways

Option 1.Try this in didFinishLaunchingWithOptions Method

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    UIApplication.shared.isStatusBarHidden = true

    return true
}

Option 2. overrideprefersStatusBarHidden function in your UIViewController

override var prefersStatusBarHidden : Bool {
    return true
}

Note: you call override func prefersStatusBarHidden it should be override var prefersStatusBarHidden

like image 94
Museer Ahamad Ansari Avatar answered Sep 21 '22 01:09

Museer Ahamad Ansari


In swift 3 use this,

override var prefersStatusBarHidden: Bool {  
    return true  
}

Reference link

like image 36
KAR Avatar answered Sep 20 '22 01:09

KAR