我的某个Xcode项目出了问题。我试图隐藏IOS应用程序的导航栏,但在时间,载体和电池部分/图标上保留白色。如果我在self.navigationController?.navigationBarHidden = false
中将navigationController设置为false,我只能将色调变为白色
当它设置为true时,色调变为白色并且没有问题,但导航栏有颜色。这是我的代码。
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")
}
}
}
}
答案 0 :(得分:1)
在视图控制器中,您可以覆盖preferredStatusBarStyle
,如下所示:
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .LightContent
}
答案 1 :(得分:0)
您的问题与导航栏无关。它与状态栏有关。您的状态栏为lightContent
,因此您会看到白色。您只需将其更改为Default
,您就会看到更好的效果。
使用viewcontroller
更改状态栏为:
将UIViewControllerBasedStatusBarAppearance设置为YES .plist文件。
在viewDidLoad中执行[self setNeedsStatusBarAppearanceUpdate];
添加以下方法:
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return .Default
}
在你的情况下是导航所以这样做:
self.navigationController.navigationBar.barStyle = .Default
希望得到这个帮助。
答案 2 :(得分:0)
状态栏样式
的 UIStatusBarStyleLightContent 强>
查看基于控制器的状态栏外观
否强>
更多信息here