1

I've been having a problem with one of my Xcode projects. I'm trying to hide the navigation bar of an IOS app, but retain a white tint on the time, carrier and battery section/icons. I can only turn the tint white if I have the navigationController set to false in self.navigationController?.navigationBarHidden = false When it is set to true, the tint turns white and there is no issue, but the navigation bar is there in color. Here is my code.

import UIKit



class ViewController: UIViewController, UITextFieldDelegate {
    @IBOutlet weak var menuButton:UIBarButtonItem!

    @IBOutlet weak var emailTxt: UITextField!
    @IBOutlet weak var passwordTxt: UITextField!
    @IBOutlet weak var signinBtn: UIButton!
    @IBOutlet weak var signupBtn: UIButton!


    var varView = Int()



    override func viewDidLoad() {


        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        emailTxt.delegate = self

        let theWidth = view.frame.size.width
        let theHeight = view.frame.size.height

        emailTxt.frame = CGRectMake(40, 200, theWidth-80, 30)
        passwordTxt.frame = CGRectMake(40, 240, theWidth-80, 30)

        signinBtn.frame = CGRectMake(theWidth-228, 340, 59, 30)

         signupBtn.frame = CGRectMake(theWidth-228, 390, 59, 30)

        let nav = self.navigationController?.navigationBar
        nav?.barStyle = UIBarStyle.Black
        nav?.tintColor = UIColor.whiteColor()
        nav?.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]

        self.navigationController?.navigationBarHidden = true








        //maparea


    }



    func textFieldShouldReturn(textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true;
    }

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    //emailTxt.resignFirstResponder()
        self.view.endEditing(true)
    }

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


    @IBAction func signInBtn(sender: AnyObject) {

        PFUser.logInWithUsernameInBackground(emailTxt.text!, password: passwordTxt.text!) {
            (user:PFUser?, error:NSError?) -> Void in

            if error == nil {

                print("logIn")
                self.performSegueWithIdentifier("gotoMainVCFromSigninVC", sender: self)

            } else {

                print("error")
            }

        }

    }

     }
vien vu
  • 4,049
  • 1
  • 15
  • 30
Larry Navarro
  • 193
  • 1
  • 1
  • 6

3 Answers3

1

In your view controller you can override preferredStatusBarStyle like this:

    override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return .LightContent
}
adrianokw
  • 388
  • 3
  • 9
0

Your problem is not relate navigation bar. It relate to status bar. Your status bar is lightContent so you will see white. You just change it to Default and you will see better.

And change status bar with viewcontroller is:

  1. Set the UIViewControllerBasedStatusBarAppearance to YES in the .plist file.

  2. In the viewDidLoad do a [self setNeedsStatusBarAppearanceUpdate];

  3. Add the following method:

    override func preferredStatusBarStyle() -> UIStatusBarStyle {
        return .Default
    }
    

In your case is navigation so do it:

self.navigationController.navigationBar.barStyle = .Default

Hope this help.

vien vu
  • 4,049
  • 1
  • 15
  • 30
0

answer of @adrianokw would be for one viewcontroller , if you want to do it for whole app add the following to info.plist

Status bar style
UIStatusBarStyleLightContent

View controller-based status bar appearance
NO

More info here

Community
  • 1
  • 1
hariszaman
  • 7,457
  • 2
  • 35
  • 53