2017-07-18 2 views
0

J'ai écrit le code suivant pour mettre en place la barre de navigation et la vue du contrôleur de vue:UINavigation Bar Couleur

  1. Barre de navigation au AppDelegate:

    var navigationController = UINavigationController() 
    
    navigationController.viewControllers = [mainViewController] 
    
  2. MainViewController A:

    self.view.backgroundColor = UIColor.blue 
    let fullScreenRect = UIScreen.main.bounds 
    let buttonSize:CGFloat = 60 
    let viewLogButton = UIButton(frame: CGRect(x: 0, y: fullScreenRect.size.height-buttonSize, width:fullScreenRect.size.width, height: buttonSize)) 
    viewLogButton.setTitle("View Log", for: UIControlState.normal) 
    viewLogButton.setTitleColor(UIColor.white, for: .normal) 
    viewLogButton.setTitleColor(UIColor.blue, for: .highlighted) 
    viewLogButton.backgroundColor = UIColor.blue 
    viewLogButton.addTarget(self, action: #selector(viewLogButtonPressed), for: .touchUpInside) 
    self.view.addSubview(viewLogButton) 
    self.webView.frame = CGRect(x: 0, y: UIConstants.NAVIGATION_BAR_HEIGHT+UIConstants.STATUS_BAR_HEIGHT, width: fullScreenRect.size.width, height: fullScreenRect.size.height-buttonSize-UIConstants.NAVIGATION_BAR_HEIGHT-UIConstants.STATUS_BAR_HEIGHT) 
    self.view.addSubview(self.webview) 
    

Cela a abouti à une vue avec la barre de navigation supérieure montre une couleur bleue semi-transparente. MainViewController A

je donc la même dans un autre ViewController B (qui est un contrôleur d'affichage de table):

  1. MainViewController B:

    let tableView = UITableView() 
    let screenSize: CGRect = UIScreen.main.bounds  
    self.view.backgroundColor = UIColor.blue 
    let screenWidth = screenSize.width 
    let screenHeight = screenSize.height 
    tableView.frame = CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight)  
    self.view.addSubview(tableView) 
    

MainViewController B

Je voudrais savoir pourquoi il y a une barre de navigation semi-transparente dans MainVi ewController A mais MainViewController B ne peut pas le montrer?

Comment puis-je faire en sorte que les deux affichent la même barre de navigation semi-transparente?

+0

subClass NavigationController et ajouter des attributs customize .Cette reflétera partout dans l'application. – Ellen

Répondre

0

Utilisez cette méthode pour changer UINavigationBar tous les lieux globaly, Appelez-de AppDelegate

func setupNaviBarAppearnce() { 

    UINavigationBar.appearance().isOpaque = true 
    UINavigationBar.appearance().isTranslucent = true 
    UINavigationBar.appearance().barTintColor = Theme.AppMainPurpleColor 
    UINavigationBar.appearance().tintColor = UIColor.white 
    UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName:Typography.navigationTitle!,NSForegroundColorAttributeName:UIColor.white] 
} 

REMARQUE: Vous devez modifier selon vos besoins et l'interface utilisateur

+0

J'ai essayé. isTranslucent, barTintColor ne sont pas disponibles dans iOS10. – user6539552

+0

non c'est '@available (iOS 3.0, *) ouvert var isTranslucent: Bool // La valeur par défaut est NO sur iOS 6 et les versions antérieures. Toujours OUI si barStyle est défini sur UIBarStyleBlackTranslucent' –

+0

pour la couleur de la barre de couleur '@available (iOS 7.0, *) open var barTintColor: UIColor? // default is nil' Just Command et cliquez sur 'barTintColor' –