iOS 7 Changing UINavigationBar titleView alpha

后端 未结 3 2033
无人共我
无人共我 2021-01-06 09:10

So I am using the UINavigationBar component of iOS7, but not the UINavigationController itself. When I push a new view with my custom navigation controller, I want to change

3条回答
  •  遥遥无期
    2021-01-06 09:35

    This is how I would do it:

    • In viewWillAppear: of the pushed viewController, I would set it the alpha to 0 using:

      [self.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                  [[UIColor whiteColor] colorWithAlphaComponent:0],
                                                                  NSForegroundColorAttributeName,
                                                                  [UIFont fontWithName:@"Helvetica-Bold" size:16.0],
                                                                  NSFontAttributeName,
                                                                   nil]];
      
    • In viewDidAppear:, set it's alpha back to 1. Here you don't really need to set it's alpha to 1, just setting it to plain [UIColor whiteColor] will do the trick.

    One other thing you could do is, toggle HIDDEN property in the 2 methods.

    Setting the alpha of the titleView did not work in my case so I used the above code. It hides the title. In case you want a similar effect with the back button, you set the alpha of the backButton using self.navigationItem.backBarButtonItem.customView.alpha =

提交回复
热议问题