2

I have the following setting in a iOS app project: "Hide status bar" is not checked.

It can be found in the general project settings under deployment info.

In AppDelegate.swift:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        window = UIWindow(frame: UIScreen.mainScreen().applicationFrame)

        window!.rootViewController = ViewController()
        window!.makeKeyAndVisible()
        // Override point for customization after application launch.
        return true
    }
...

In ViewController.swift:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        view.backgroundColor = UIColor.blueColor()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func prefersStatusBarHidden() -> Bool {
        return true;
    }
}

I got the following result (unfortunately, I'm a new member and don't have enough rep. to post images): Most of the screen is blue, except the very top (where the status bar should show), which is black.

Can anyone explain to me why the top is black, and how to fix it (e.g. turn it into blue)?

Fine Man
  • 455
  • 4
  • 17
  • regarding the image: just upload it somewhere and post a link - mods will insert the image for you. regarding your question: have you checked http://stackoverflow.com/questions/26146012/hide-status-bar-in-ios-8-app ? – luk2302 Jun 07 '15 at 19:02
  • Well you are setting it to hidden in your code – Leo Dabus Jun 07 '15 at 19:06
  • just upload it on imgur or basically any image upload site. – luk2302 Jun 07 '15 at 19:13

1 Answers1

2

The top is black because this line is wrong:

window = UIWindow(frame: UIScreen.mainScreen().applicationFrame)

It should be:

window = UIWindow(frame:UIScreen.mainScreen().bounds)
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Thanks a lot Matt!!! I have another favor to ask: Do you have some source about iOS app architecture? I'm not exactly sure what a UIWindow is, App Delegate is, etc, and how they tie into an app. – Fine Man Jun 07 '15 at 19:20
  • Basically the moral here is: if you are going to take charge of launching your app manually in code, as you are doing in `didFinishLaunchingWithOptions:`, you must do it correctly! :) This is why most people use a storyboard and let all this stuff get taken care of for them. However, don't get the wrong idea - I am not criticizing, just pointing out the risks. On the contrary, I admire your willingness to give manual launching a try, and I personally use it all the time. – matt Jun 07 '15 at 19:21
  • Click on my icon and read my Profile to learn what "source" I have... :) – matt Jun 07 '15 at 19:21
  • Okay, thanks! I'll look into it. I really dislike storyboards because I feel as if I don't have full control over my app. It's quite ironic actually. All the famous developers who make tutorials claim that make apps completely programmatically is their preferred way, yet they have no tutorials on it!!! :-) – Fine Man Jun 07 '15 at 19:25
  • I totally agree about storyboards; that is why I said I'm not criticizing. But then, as I said, if you're going to do the dance manually, you must do the dance correctly or Bad Things will happen - as you've already discovered. – matt Jun 07 '15 at 19:27
  • So, do your books talk about app architecture and an app's lifecycle? Also, I have a very small budget (approx. $0 :-)), so do you know of any good free sources? – Fine Man Jun 07 '15 at 19:28
  • You could read the free online version of my book, but it is somewhat out of date: http://www.apeth.com/iOSBook/ – matt Jun 07 '15 at 19:41