iOS 7更改UINavigationBar titleView alpha [英] iOS 7 Changing UINavigationBar titleView alpha
问题描述
所以我使用的UINavigationBar组件的iOS7,但不是UINavigationController本身。当我使用自定义导航控制器推新视图时,我想将标题的alpha更改为0.0,然后返回,但我似乎无法使其工作。
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 the title's alpha to 0.0 and then back, but I can't seem to get it work.
我试图这样做
vc1.navBar.topItem.titleView.alpha = 0.1;
它似乎没有任何效果。
It doesn't seem to have any effect. Am I missing something here, is there a correct way to achieve this?
推荐答案
这是我该怎么办:
-
在推送的viewController的
viewWillAppear:
to 0 using:
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]];
在 viewDidAppear:
它的alpha返回到1.这里你真的不需要设置它的alpha为1,只要设置为简单 [UIColor whiteColor]
会做的伎俩。
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.
您可以做的另一件事是,切换 HIDDEN
2方法。
One other thing you could do is, toggle HIDDEN
property in the 2 methods.
设置titleView的alpha不适用于我的情况,所以我使用上面的代码。它隐藏标题。如果你想要一个类似的效果与后退按钮,你设置的backButton的alpha使用 self.navigationItem.backBarButtonItem.customView.alpha =
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 =
这篇关于iOS 7更改UINavigationBar titleView alpha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!